我在使用模块urllib(Python 3.6)时遇到了问题。每次使用该模块时,我都会收到相当于一页的错误。
urllib有什么问题以及如何修复?
import urllib.request
url='https://www.goodreads.com/quotes/tag/artificial-intelligence'
u1 = urllib.request.urlopen(url)
print(u1)
这段代码喜欢吐出一口东西:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/a-nguyen/Downloads/EzSorses/APAsauce.py", line 3, in <module>
u1 = urllib.request.urlopen(url)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>
好像模块本身出了问题。
我也有同样的问题。我的python版本是3.6.5,我在Mac OSX上。当我试图连接到HTTPS
网站时,我开始得到
例外因此,很明显,我的机器上的python没有证书。我刚刚从路径
/Applications/Python 3.6
运行了该文件,文件名为InstallCertificates。命令
。这解决了我的问题。我参考了这篇文章。
一个肮脏的(在安全方面不安全)但像这样的快速黑客为我做的工作:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
有一个命令行程序,您可以在MacOsX上运行,它将安装证书:
sudo /Applications/Python\ 3.6/Install\ Certificates.command
sudo
命令将提示您输入密码以提升您的权限。
执行简单代码后: 我有下一个错误: Traceback(最近一次调用最后一次):文件"F:\Run\Lpror\Phyton\lib\site-包\urllib3\connectionpool.py",第597行,在urlopenf中。_prepare_proxy(conn)文件"F:\Run\Lpror\Phyton\lib\site-包\urllib3\connectionpool.py",第
我正在练习'Web Scraping with Python'中的代码,我一直遇到这个证书问题: 错误是: 顺便说一句,我也在练习scrapy,但一直遇到问题:command not found:scrapy(我在网上尝试了各种解决方案,但都没有奏效……真令人沮丧)
我正在使用节点0.10.26,并试图通过客户端验证建立https连接。 服务器代码: 客户代码: 我使用以下命令创建了证书,每次都将“uname-n”的结果作为“Common Name”提供: 我已经使用客户端和服务器证书的所有组合(即:[(server1,client1),(server1,client2),(server2,client1),(server2,client1),(server2
误差 PHP警告:stream_socket_client():SSL操作失败,代码为1。OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_Server_Certifice:证书验证失败
问题内容: 我正在尝试通过调用HTTPS REST API 。在开发过程中,我偶然发现以下错误: 因此,我在Google上搜索了一下,并找到了很多可行的解决方案。 使用Jersey客户端的HTTPS https://gist.github.com/outbounder/1069465 如何解决“ java.security.cert.CertificateException:不存在使用者替代名称”
问题内容: 假设我编写了两个Java应用程序:并且它们被部署并在两个单独的服务器上运行(部署到和部署到),并且这两个应用程序需要通过SSL相互通信(双向)。我们还假设每个应用程序都有自己的SSL证书。 我(Java程序员)如何编码并验证彼此的SSL证书?每个CA是否都提供某种我可以使用的RESTful API ?Java是否有自己的证书验证API?我可以使用开放源代码的第三方JAR或服务吗? 当我