(python) Socket.gaierror On Every Addres...except Http://www.reddit.com?
I'm just playing around and I'm trying to grab information from websites. Unfortunately, with the following code: import sys import socket import re from urlparse import urlsplit
Solution 1:
Please please please please please please please don't do this.
urllib and urllib2 are your friends.
Read the "missing" urllib2 manual if you are having trouble with it.
Solution 2:
sock.connect((url[0] + '://' + url[1],80))
Do not do that, instead do this:
sock.connect((url[1], 80))
connect
expects a hostname, not a URL.
Actually, you should probably use something higher-level than sockets to do HTTP. Maybe httplib.
Solution 3:
you forgot to resolve the hostname:
addr = socket.gethostbyname(url[1])
...
sock.connect((addr,80))
Post a Comment for "(python) Socket.gaierror On Every Addres...except Http://www.reddit.com?"