[英]Why does python return an error when using urllib.request.urlopen for certain websites
when I use url lib.requests in python 3, it works for some websites but for others it returns an error: 当我在python 3中使用url lib.requests时,它适用于某些网站,但对于其他网站则返回错误:
import urllib.request
urllib.request.urlopen('wikipedia.org')
Traceback (most recent call last):
File "/Users/etudiant/Desktop/test.py", line 3, in <module>
urllib.request.urlopen('wikipedia.org')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 510, in open
req = Request(fullurl, data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 328, in __init__
self.full_url = url
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 354, in full_url
self._parse()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 383, in _parse
raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: 'wikipedia.org'
>>>
You need to change url to: 您需要将网址更改为:
It should work now. 现在应该可以工作了。
Try this : 尝试这个 :
import urllib.request
urllib.request.urlopen('https://www.wikipedia.org/')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.