[英]Python-How to solve ssl.SSLError: [SSL: CA_MD_TOO_WEAK]
I've got a huge problem with authorization of my API request.我的 API 请求的授权遇到了一个大问题。 I'm using python 3.10.
我正在使用 python 3.10。 For setting up the client I have code as follows:
为了设置客户端,我有如下代码:
from zeep import exceptions, helpers
from requests import Session
from zeep.transports import Transport
from zeep import Client
def login(register):
.......
elif register == 'XXX':
authTok = '' #only for coherence
wsdl_path = r"path_to_my_wsdl.wsdl"
url = urllib.parse.urljoin('file:', urllib.request.pathname2url(os.path.abspath(wsdl_path)))
session = Session()
session.verify = False
session.cert = (r'path_to_my_cert.pem')
client = Client(wsdl=url, transport=Transport(session=session))
return client, authTok
Then I used code below to get the client:然后我使用下面的代码来获取客户端:
client, authTok = login('XXX')
search = {}
search['sort'] = {'sort_att': 'number',
'sort_asc': 'True'}
search['criterion'] = {'search_range': 'RP', 'id': '123456789'}
No error till this step.直到这一步没有错误。 And finally I've tried to send my request like this:
r = client.service.searchcompany(params=search)
最后我尝试像这样发送我的请求:
r = client.service.searchcompany(params=search)
Here I got error like this:在这里我得到这样的错误:
ssl.SSLError: [SSL: CA_MD_TOO_WEAK] ca md too weak (_ssl.c:3862)
With openssl I've generated new cert:使用 openssl 我生成了新证书:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out mycert.pem -sha256 -days 365 -nodes
As the output I've received two files: key.pem and mycert.pem.作为 output,我收到了两个文件:key.pem 和 mycert.pem。 With command
certifi.where()
I found location of my file cacert.pem and pasted into it the content of file mycert.pem.使用命令
certifi.where()
我找到了文件 cacert.pem 的位置并将文件 mycert.pem 的内容粘贴到其中。
Unfortunately the error still occurs.不幸的是,错误仍然发生。 Could anybody explain what I'm doing wrong?
谁能解释我做错了什么?
In my case it was helpful to downgrade the version of python to 3.8.8.就我而言,将 python 的版本降级到 3.8.8 很有帮助。 That solved my error.
这解决了我的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.