Python requests.exceptions.SSLError:EOF违反协议 [英] Python requests.exceptions.SSLError: EOF occurred in violation of protocol
问题描述
我会从提供RESTful JSON API的ABB G13网关中检索一些信息。 API由网关通过https端点托管。
基本身份验证机制用于身份验证。但是所有流量
都通过SSL层。
I would retrieve some information from an ABB G13 gateway that offer a RESTful JSON API. API is hosted by the gateway via https endpoint. Basic authentication mechanism is used for authentication. However all traffic goes through SSL layers.
在Linux上使用命令:
On linux with command:
curl -s -k -X GET -u user:password https://host/meters/a_serial/power
一切顺利!
我正在尝试在Python 2.7.10中使用请求2.8.1编写一个Windows脚本此代码:
I'm trying to write a script for windows in Python 2.7.10 with Requests 2.8.1 and with this code:
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)
我搜索了一个解决方案,我试图修复此代码:
I've searched for a solution and I've tried to fix with this code:
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')
但它不适合我,因为我收到此错误:
But it doesn't work for me cause I get this error:
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)
我遇到了这个问题。有人能帮帮我吗?谢谢!
I'm stuck on this problem. Could someone help me? Thanks!
推荐答案
这件事对我有用,只要确定是否安装了这些模块,如果没有安装它们,以下是:
This thing worked for me ,just make sure whether these modules are installed or not ,if not then install them, following are:
pip install ndg-httpsclient
pip install pyopenssl
pip install pyasn1
它删除了我的SSLError:EOF违反协议(_ssl.c:590) )错误。
It removed my SSLError: EOF occurred in violation of protocol (_ssl.c:590) error.
希望它有所帮助。
这篇关于Python requests.exceptions.SSLError:EOF违反协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!