urllib不能使用python3

时间:2016-01-31 09:37:37

标签: python-3.x urllib2 python-3.4 urllib

我刚刚开始学习python,我已经达到了向模块urllib介绍的地步。当我执行一些代码时:

import urllib.request

x=urllib.request.urlopen('https://www.google.com')
print(x.read())

shell输出给了我类似的东西:

Traceback (most recent call last):
File "/usr/lib/python3.4/urllib/request.py", line 1182, in do_open

h.request(req.get_method(), req.selector, req.data, headers)
File "/usr/lib/python3.4/http/client.py", line 1088, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.4/http/client.py", line 1126, in _send_request
self.endheaders(body)
File "/usr/lib/python3.4/http/client.py", line 1084, in endheaders

self._send_output(message_body)
File "/usr/lib/python3.4/http/client.py", line 922, in _send_output
self.send(msg)
File "/usr/lib/python3.4/http/client.py", line 857, in send
self.connect()
File "/usr/lib/python3.4/http/client.py", line 1223, in connect

super().connect()
File "/usr/lib/python3.4/http/client.py", line 834, in connect

self.timeout, self.source_address)
File "/usr/lib/python3.4/socket.py", line 512, in create_connection
raise err
File "/usr/lib/python3.4/socket.py", line 503, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/kibzyzii/Devt/python/practise/tuts/webcrawler.py", line 11, in <module>
x=urllib.request.urlopen('https://www.google.com')
File "/usr/lib/python3.4/urllib/request.py", line 161, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.4/urllib/request.py", line 463, in open
response = self._open(req, data)
File "/usr/lib/python3.4/urllib/request.py", line 481, in _open
'_open', req)
File "/usr/lib/python3.4/urllib/request.py", line 441, in _call_chain
result = func(*args)
File "/usr/lib/python3.4/urllib/request.py", line 1225, in https_open

context=self._context, check_hostname=self._check_hostname)
File "/usr/lib/python3.4/urllib/request.py", line 1184, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 110] Connection timed out>

这是python 3.4.3。我还在 virtualenv 中尝试了python 3.5。但是,它产生了类似的输出。
我正在使用ubuntu 14.04.3lts。任何帮助将不胜感激。

0 个答案:

没有答案