Reputation: 79
I hope to access the text file from the following url:
http://www.pythonlearn.com/code/intro-short.txt
My code is
import socket
socket.getaddrinfo('127.0.0.1', 8080)
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('http://www.pythonlearn.com', 80))
mysock.send('GET http://www.pythonlearn.com/code/intro-short.txt HTTP/1.0\n\n')
I keep getting an error: gaierror: [Errno 11004] getaddrinfo failed
Can you help me with this?
Thanks.
Upvotes: 3
Views: 25643
Reputation: 96
In mysock.connect(('http://www.pythonlearn.com', 80))
, the first element in the tuple should be just the host name (or address), without 'http://'.
So mysock.connect(('www.pythonlearn.com', 80))
should work.
Incidentally, socket.getaddrinfo('127.0.0.1', 8080)
would get the address information for your local host, not the server you want to contact; so this statement seems unnecessary.
Upvotes: 4