Hi all,
I am trying to connect to a website (also see: http://forum.micropython.org/viewtopic.php?f=11&t=1089).
All the samples I see, first resolve the hostname to an ip-address using: socket.getaddrinfo and then call socket.connect, eg:
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sockaddr = socket.getaddrinfo('www.google.com', 80)[-1][4]
>>> print(sockaddr)
('74.125.136.104', 80)
>>> s.connect(sockaddr)
However, when I try to connect passing a tuple containing hostname and port, an error occurs:
>>> s.connect(('www.google.com', 80))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid arguments
Should it be possible to call socket.connect with the hostname? If so, which mistake am I overlooking?
TIA
/Ronald
socket.connect using hostname
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: socket.connect using hostname
Hi Ronald,
No, that's not possible, you need to pass the IP address.
Cheers,
Daniel
No, that's not possible, you need to pass the IP address.
Cheers,
Daniel