我正在练习'Web Scraping with Python'中的代码,我一直遇到这个证书问题:
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
pages = set()
def getLinks(pageUrl):
global pages
html = urlopen("http://en.wikipedia.org"+pageUrl)
bsObj = BeautifulSoup(html)
for link in bsObj.findAll("a", href=re.compile("^(/wiki/)")):
if 'href' in link.attrs:
if link.attrs['href'] not in pages:
#We have encountered a new page
newPage = link.attrs['href']
print(newPage)
pages.add(newPage)
getLinks(newPage)
getLinks("")
错误是:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1049)>
顺便说一句,我也在练习scrapy,但一直遇到问题:command not found:scrapy(我在网上尝试了各种解决方案,但都没有奏效……真令人沮丧)
要解决这个问题:
您所需要做的就是安装Python证书!macOS上的一个常见问题。
打开以下文件:
Install Certificates.command
Update Shell Profile.command
只要运行这两个脚本,您就不会再有这个问题了。
希望这有帮助!
要使用未经验证的ssl,您可以将其添加到代码中:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
曾几何时,我在这个问题上遇到了麻烦。如果您正在使用macOS,请转到Macintosh HD
我在使用模块urllib(Python 3.6)时遇到了问题。每次使用该模块时,我都会收到相当于一页的错误。 urllib有什么问题以及如何修复? 这段代码喜欢吐出一口东西: 好像模块本身出了问题。
执行简单代码后: 我有下一个错误: Traceback(最近一次调用最后一次):文件"F:\Run\Lpror\Phyton\lib\site-包\urllib3\connectionpool.py",第597行,在urlopenf中。_prepare_proxy(conn)文件"F:\Run\Lpror\Phyton\lib\site-包\urllib3\connectionpool.py",第
误差 PHP警告:stream_socket_client():SSL操作失败,代码为1。OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_Server_Certifice:证书验证失败
问题内容: 在Windows Vista SP2 + Python 2.7.10上,我可以连接到https://www.python.org,但不能连接到https://codereview.appspot.com 剧本: 并输出: 如何解决问题,https://codereview.appspot.com/到底有什么问题? 问题答案: 我的猜测是,它与OpenSSL中的替代链处理有关,如Pyth
问题内容: 这段代码 给我这个错误 我对SSL几乎一无所知,但我曾尝试下载该站点的证书并使用该选项指向该文件,但是它没有用。我想念什么吗? 问题答案: 正如评论中已经指出的那样:从SSLLabs报告中可以看出,该网站的SSL实施不正确。该报告中有关您的问题的主要部分是: 该服务器的证书链不完整。等级上限为B。 这意味着服务器没有发送验证证书所需的完整证书链。这意味着您需要在验证时自行添加丢失的证书