gpt4 book ai didi

python - SSL:Windows 上的 CERTIFICATE_VERIFY_FAILED 错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:37:37 25 4
gpt4 key购买 nike

我正在构建一个简单的程序来遍历 URL 列表并使用 beautiful soup 提取其内容。目前我只是试图遍历列表并检索 html,但我不断收到以下错误:

Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 964, in send
self.connect()
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1400, in connect
server_hostname=server_hostname)
File "C:\ProgramData\Anaconda3\lib\ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "C:\ProgramData\Anaconda3\lib\ssl.py", line 808, in __init__
self.do_handshake()
File "C:\ProgramData\Anaconda3\lib\ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "C:\ProgramData\Anaconda3\lib\ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/thoma/PycharmProjects/fyp/urls_and_prep/parsing_html.py", line 17, in <module>
response = urllib.request.urlopen(req)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\ProgramData\Anaconda3\lib\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:749)>

我的程序很简单,但我无法理解或找不到任何好的资源来弄清楚到底发生了什么/如何处理它。我知道它与 SSL 证书有关,但我不确定如何使用它们或在哪里安装它们等。我对这个有点不知所措,因为我以前从未真正使用过 SSL .非常感谢任何指导或帮助。这是代码:

import urllib.request
from bs4 import BeautifulSoup

file = open("all_urls.txt", "r")

for line in file:
print(line)

try:
response = urllib.request.urlopen(line)
html = response.read()
except ValueError:
print(ValueError)
continue
soup = BeautifulSoup(html, 'lxml')
print(soup.get_text())

最佳答案

您使用的是 Windows 还是 Linux?这个问题好像不是出在Python上,而是出在Anaconda或者OS上。您可以尝试一些简单的解决方案,例如: 1 - 使用不同于 Anaconda 的其他 Python 安装来执行 scrypt。 2 - 使用 virtualenv 隔离操作系统的组件。

关于python - SSL:Windows 上的 CERTIFICATE_VERIFY_FAILED 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46285063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com