gpt4 book ai didi

Python 请求.exceptions.SSLError : EOF occurred in violation of protocol

转载 作者:太空狗 更新时间:2023-10-29 20:42:01 25 4
gpt4 key购买 nike

我将从提供 RESTful JSON API 的 ABB G13 网关检索一些信息。 API 通过 https 端点由网关托管。基本认证机制用于认证。然而所有的交通通过 SSL 层。

在 linux 上使用命令:

curl -s -k -X GET -u user:password https://host/meters/a_serial/power

一切顺利!

我正在尝试使用 Requests 2.8.1 和以下代码在 Python 2.7.10 中为 Windows 编写脚本:

import requests
requests.get('https://host/meters/a_serial/power', auth=('user', 'password'))

我有这个错误:

Traceback (most recent call last):
File "C:/Users/mzilio/PycharmProjects/pwrgtw/test.py", line 20, in <module>
requests.get('https://host/meters/a_serial/power', auth=('user', 'password'))
File "C:\Python27\lib\site-packages\requests\api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 433, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:590)

我已经搜索了一个解决方案,并尝试使用以下代码进行修复:

import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl

class MyAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=ssl.PROTOCOL_TLSv1)

s = requests.Session()
s.mount('https://', MyAdapter())
s.get('https://host/meters/a_serial/power')

但它对我不起作用,因为我收到此错误:

Traceback (most recent call last):
File "C:/Users/mzilio/PycharmProjects/pwrgtw/test.py", line 16, in <module>
s.get('https://host/meters/a_serial/power')
File "C:\Python27\lib\site-packages\requests\sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 433, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:590)

我被困在这个问题上了。有人可以帮我吗?谢谢!

最佳答案

这个东西对我有用,只要确保这些模块是否安装,如果没有安装它们,以下是:

pip install ndg-httpsclient

pip install pyopenssl

pip install pyasn1

它消除了我的 SSLError: EOF occurred in violation of protocol (_ssl.c:590) 错误。

希望对您有所帮助。

关于Python 请求.exceptions.SSLError : EOF occurred in violation of protocol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33410577/

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