相关疑难解决方法(0)

urllib和"SSL:CERTIFICATE_VERIFY_FAILED"错误

我收到以下错误:

Exception in thread Thread-3:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in        __bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in  run
self.__target(*self.__args, **self.__kwargs)
File "/Users/Matthew/Desktop/Skypebot 2.0/bot.py", line 271, in process
info = urllib2.urlopen(req).read()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File …
Run Code Online (Sandbox Code Playgroud)

python ssl urllib ssl-certificate python-2.7

250
推荐指数
19
解决办法
55万
查看次数

Mac OSX python ssl.SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:749)

python中的许多操作都需要通过https访问.这包括pip安装,或仅使用http.client.HTTPSConnection,或内部使用这些内容的任何模块或应用程序.

如果python是从官方的python pkg安装程序安装的,从https://python.org下载,那么它使用的是openssl的内部版本,并且不包含根证书.任何使用SSL连接的内容都会导致此错误:

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
Run Code Online (Sandbox Code Playgroud)

如何安装根证书以使上述错误消失?

python macos ssl

51
推荐指数
6
解决办法
4万
查看次数

在python中使用请求时无法获取本地颁发者证书

这是我的代码

import requests;
url='that website';
headers={
  'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7',
  'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
};
r = requests.get(url,headers=headers);
print(r);
print(r.status_code);
Run Code Online (Sandbox Code Playgroud)

然后它遇到了这个:

requests.exceptions.SSLError:

HTTPSConnectionPool(host='www.xxxxxx.com', port=44 3):

url: xxxxxxxx 超出最大重试次数(由 SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED]

证书验证失败:无法获得本地颁发者证书 (_ssl.c:1045)')))

我该怎么办?

python python-requests

47
推荐指数
6
解决办法
10万
查看次数

urllib.error.URLError: <urlopen 错误 [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1108)

import yfinance as yf
Run Code Online (Sandbox Code Playgroud)

msft = yf.Ticker("MSFT")

微软信息网

我尝试打印 msft.info 并收到“urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1108)”错误。我尝试重新运行 Install Certificates.command 和 Update Sheet.command 但显然它不起作用。另外,在我重新运行它们之后,我得到了这个消息: 由于环境错误无法安装软件包:[Errno 13]权限被拒绝:'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ certifi-2021.5.30.dist-info。

有什么建议我该如何修复它吗?

python macos python-3.8

31
推荐指数
2
解决办法
8万
查看次数

证书验证失败:无法获取本地颁发者证书

我正在尝试使用python从网络获取数据。我为此导入了urllib.request包,但是在执行时出现错误:

certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)
Run Code Online (Sandbox Code Playgroud)

当我将网址更改为“ http”时-我可以获取数据。但是,我相信,这避免了检查SSL证书。

所以我检查了互联网,找到了一个解决方案:运行 /Applications/Python\ 3.7/Install\ Certificates.command

这解决了我的问题。但是我对SSL之类的东西一无所知。您能否帮助我了解它实际上解决了我的问题。

如果可能,请向我推荐任何有用的资源,以了解有关安全性和证书的信息。我是新来的。

谢谢!

注意:我确实通过链接-openssl,python请求错误:“证书验证失败”

我的问题与链接中的问题不同,因为我想知道在安装certifi软件包或运行Install\ Certificates.command该错误时实际发生了什么。我对证券知之甚少。

python ssl openssl python-3.x

29
推荐指数
14
解决办法
3万
查看次数

抓取https://www.thenewboston.com/时出现"SSL:certificate_verify_failed"错误

所以我最近在youtube上使用"新波士顿"视频开始学习Python,一切都很顺利,直到我开始制作一个简单的网络爬虫教程.虽然我理解它没有问题,但当我运行代码时,我得到的错误似乎都基于"SSL:CERTIFICATE_VERIFY_FAILED".自昨晚以来我一直在寻找答案,试图弄清楚如何修复它,似乎没有其他人在视频或他的网站上的评论中遇到与我相同的问题,甚至使用他的某些人的代码网站我得到了相同的结果.我将从网站上发布的代码发布代码,因为它给了我同样的错误,而我编码的代码现在变得一团糟.

import requests
from bs4 import BeautifulSoup

def trade_spider(max_pages):
    page = 1
    while page <= max_pages:
        url = "https://www.thenewboston.com/forum/category.php?id=15&orderby=recent&page=" + str(page) #this is page of popular posts
        source_code = requests.get(url)
        # just get the code, no headers or anything
        plain_text = source_code.text
        # BeautifulSoup objects can be sorted through easy
        for link in soup.findAll('a', {'class': 'index_singleListingTitles'}): #all links, which contains "" class='index_singleListingTitles' "" in it.
            href = "https://www.thenewboston.com/" + link.get('href')
            title = link.string # just the text, not the HTML …
Run Code Online (Sandbox Code Playgroud)

python ssl ssl-certificate web-scraping

19
推荐指数
4
解决办法
8万
查看次数

Brew 3.6.1的Brew安装:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败

我安装了python 3.6

brew install python3

并尝试six.moves.urllib.request.urlretrieve从https 下载文件,但它会引发错误

ssl.SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:749)

在Python安装(从.pkg)的,自述指示一个需要运行Install Certificates.command在安装后

  1. 安装 certifi
  2. 符号链接路径的证书certify路径

能够使用证书.

但是,在brew安装中,此文件不存在,似乎不会运行.

python ssl

15
推荐指数
5
解决办法
1万
查看次数

Python urllib urlopen无法正常工作

我只是想通过使用urllib模块从实时网络中获取数据,所以我写了一个简单的例子

这是我的代码:

import urllib

sock = urllib.request.urlopen("http://diveintopython.org/") 
htmlSource = sock.read()                            
sock.close()                                        
print (htmlSource)  
Run Code Online (Sandbox Code Playgroud)

但我得到的错误如下:

Traceback (most recent call last):
  File "D:\test.py", line 3, in <module>
    sock = urllib.request.urlopen("http://diveintopython.org/") 
AttributeError: 'module' object has no attribute 'request'
Run Code Online (Sandbox Code Playgroud)

python urllib

10
推荐指数
3
解决办法
5万
查看次数

ssl.SSLCertVerificationError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:证书已过期(_ssl.c:997)

当我尝试将框架aiohhtp与以下代码(取自文档)一起使用时,我正在使用一些 Python 网络框架:

import aiohttp
import asyncio

#********************************
# a solution I found on the forum:
# /sf/ask/3516528221/?rq=1
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
# ... but it doesn't work :(
#********************************

async def main():

    async with aiohttp.ClientSession() as session:
        async with session.get("https://python.org") as response:

            print("Status:", response.status)
            print("Content-type:", response.headers["content-type"])

            html = await response.text()
            print("Body:", html[:15], "...")

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Run Code Online (Sandbox Code Playgroud)

当我运行这段代码时,我得到了这个回溯:

DeprecationWarning: There is 
no current event loop
  loop = asyncio.get_event_loop()
Traceback (most recent call last):
  File "c:\Python310\lib\site-packages\aiohttp\connector.py", line 986, …
Run Code Online (Sandbox Code Playgroud)

python ssl ssl-certificate python-3.x aiohttp

9
推荐指数
1
解决办法
4万
查看次数

如何从烧瓶中调用另一个webservice api

我在我的烧瓶服务器中使用重定向来调用另一个webservice api.eg

@app.route('/hello')
def hello():
    return redirect("http://google.com")
Run Code Online (Sandbox Code Playgroud)

该网址逻辑上更改为google.com,但有什么方法可以保持相同的网址?或任何其他方式来获得webservice调用.

python flask

8
推荐指数
1
解决办法
2万
查看次数

Python 3 和 Slack 客户端:ssl.SSLCertVerificationError

我正在尝试在 python 3.8 中访问 Slack,但我无法通过第一步。这是我的代码:

import slack

slack_token="xoxp-*******-*******-*******-*******"
client = slack.WebClient(slack_token)

client.chat_postMessage(
    channel="XXXXXXXXXX",
    text="Hello from your app! :tada:"
)

print('hello')

Run Code Online (Sandbox Code Playgroud)

这是错误:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/aiohttp/connector.py", line 936, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 1046, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 1076, in _create_connection_transport
    await waiter
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/sslproto.py", line 529, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line …
Run Code Online (Sandbox Code Playgroud)

python-3.x slack

5
推荐指数
2
解决办法
1901
查看次数