python 2.7 报错

Traceback (most recent call last):
File "/usr/lib/python3.2/urllib/request.py", line 1140, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "/usr/lib/python3.2/http/client.py", line 970, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.2/http/client.py", line 1008, in _send_request
self.endheaders(body)
File "/usr/lib/python3.2/http/client.py", line 966, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.2/http/client.py", line 811, in _send_output
self.send(msg)
File "/usr/lib/python3.2/http/client.py", line 749, in send
self.connect()
File "/usr/lib/python3.2/http/client.py", line 727, in connect
self.timeout, self.source_address)
File "/usr/lib/python3.2/socket.py", line 397, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "python4beg.py", line 14, in <module>
response = request.urlopen('http://pythonforbeginners.com/')
File "/usr/lib/python3.2/urllib/request.py", line 139, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.2/urllib/request.py", line 370, in open
response = self._open(req, data)
File "/usr/lib/python3.2/urllib/request.py", line 388, in _open
'_open', req)
File "/usr/lib/python3.2/urllib/request.py", line 348, in _call_chain
result = func(*args)
File "/usr/lib/python3.2/urllib/request.py", line 1160, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/lib/python3.2/urllib/request.py", line 1143, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -5] No address associated with hostname>

 

/usr/local/python2.7/lib/python2.7/socket.py

Original Code:

def create_connection(.....)

host, port = address
err = None
for res in getaddrinfo(host, port, 0, SOCK_STREAM):

Edited Code:

def create_connection(.....)

host, port = address
err = None
hostip = gethostbyname(host)
for res in getaddrinfo(hostip, port, 0, SOCK_STREAM):

发表评论