爬虫:我的urlopen为什么弹出来红色代码,求救
按照甲鱼视频来的,一模一样的代码,我的报错,求大神指导!
本帖最后由 Twilight6 于 2020-8-2 12:54 编辑
qq13700416415 发表于 2020-8-2 12:49
试试这样运行,跳过下证书验证:
import ssl
import urllib.request
ssl._create_default_https_context = ssl._create_unverified_context
response = urllib.request.urlopen("http://www.fishc.com") 发代码……而且才悬赏 1 鱼币,太没诚意了吧 zltzlt 发表于 2020-8-2 12:35
发代码……而且才悬赏 1 鱼币,太没诚意了吧
我鱼B好少,哈哈,我多去赚点 qq13700416415 发表于 2020-8-2 12:36
我鱼B好少,哈哈,我多去赚点
普通求助帖都比你悬赏的高...所以说你还不如不设置悬赏,还不用浪费你鱼币{:10_245:}
你的报错最后几行发上来,截图看不见,代码也顺便 copy 下发下吧
qq13700416415 发表于 2020-8-2 12:36
我鱼B好少,哈哈,我多去赚点
把你的代码传上来吧 >>> import urllib.request
>>> response = urllib.request.urlopen("http://www.fishc.com")
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1350, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1010, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 950, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1424, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
response = urllib.request.urlopen("http://www.fishc.com")
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 563, in error
result = self._call_chain(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 755, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 563, in error
result = self._call_chain(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 755, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1393, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1353, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>
>>>
代码已传,谢谢各位大佬 import urllib.request
response = urllib.request.urlopen("http://www.fishc.com") Twilight6 发表于 2020-8-2 12:35
试试这样运行,跳过下证书验证:
这是什么操作,小甲鱼没讲过。。 qq13700416415 发表于 2020-8-2 12:49
现在的鱼C论坛都支持 https 了,
但是代码里还是 http(历史遗留问题) Twilight6 发表于 2020-8-2 12:38
普通求助帖都比你悬赏的高...所以说你还不如不设置悬赏,还不用浪费你鱼币
你的报错 ...
我刚试了下,我每次要打开urlopen都得运行ssl,为啥这样子。。哭 qq13700416415 发表于 2020-8-2 13:08
我刚试了下,我每次要打开urlopen都得运行ssl,为啥这样子。。哭
我也不懂,我都不用加都可以打开的哈哈
Twilight6 发表于 2020-8-2 13:32
我也不懂,我都不用加都可以打开的哈哈
晕,难道我的是阉割版的python 试一下编辑器,新版本的用编辑器就可以
页:
[1]