import urllib.request
url="http://www.baidu.com"
req=urllib.request.urlopen(url)
然后报错
Traceback (most recent call last):
File "D:\python344\lib\urllib\request.py", line 1183, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "D:\python344\lib\http\client.py", line 1137, in request
self._send_request(method, url, body, headers)
File "D:\python344\lib\http\client.py", line 1182, in _send_request
self.endheaders(body)
File "D:\python344\lib\http\client.py", line 1133, in endheaders
self._send_output(message_body)
File "D:\python344\lib\http\client.py", line 963, in _send_output
self.send(msg)
File "D:\python344\lib\http\client.py", line 898, in send
self.connect()
File "D:\python344\lib\http\client.py", line 871, in connect
self.timeout, self.source_address)
File "D:\python344\lib\socket.py", line 516, in create_connection
raise err
File "D:\python344\lib\socket.py", line 507, in create_connection
sock.connect(sa)
OSError: [WinError 10013] 以一种访问权限不允许的方式做了一个访问套接字的尝试。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
req=urllib.request.urlopen(url)
File "D:\python344\lib\urllib\request.py", line 161, in urlopen
return opener.open(url, data, timeout)
File "D:\python344\lib\urllib\request.py", line 464, in open
response = self._open(req, data)
File "D:\python344\lib\urllib\request.py", line 482, in _open
'_open', req)
File "D:\python344\lib\urllib\request.py", line 442, in _call_chain
result = func(*args)
File "D:\python344\lib\urllib\request.py", line 1211, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "D:\python344\lib\urllib\request.py", line 1185, in do_open
raise URLError(err)
urllib.error.URLError: