gpt4 book ai didi

Python HTTPS 请求 SSLError CERTIFICATE_VERIFY_FAILED

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:08 26 4
gpt4 key购买 nike

python

import requests

url = "https://REDACTED/pb/s/api/auth/login"

r = requests.post(
url,
data = {
'username': 'username',
'password': 'password'
}
)

尼姆

import httpclient, json

let client = newHttpClient()

client.headers = newHttpHeaders({ "Content-Type": "application/json" })
let body = %*{
"username": "username",
"password": "password"
}

let resp = client.request("https://REDACTED.com/pb/s/api/auth/login", httpMethod = httpPOST, body = $body)

echo resp.body

我正在调用 API 来获取一些数据。运行 python 代码,我得到了下面的回溯。但是,nim 代码运行良好,因此 python 代码或设置一定有问题。

我正在运行 Python 2.7.15 版。请求 lib 版本 2.19.1

Traceback (most recent call last):
File "C:/Python27/testht.py", line 21, in <module>
"Referer": "https://REDACTED.com/pb/a/"
File "C:\Python27\lib\site-packages\requests\api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 511, in send
raise SSLError(e, request=request)
SSLError: HTTPSConnectionPool(host='REDACTED.com', port=443): Max retries exceeded with url: /pb/s/api/auth/login (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)'),))

最佳答案

requests 模块将验证它从服务器获得的证书,就像浏览器一样。 requests 将引发该异常,而不是像您在浏览器中那样点击并说出“添加异常”。

但有一种解决方法:尝试将 verify=False 添加到您的 post 调用中。

关于Python HTTPS 请求 SSLError CERTIFICATE_VERIFY_FAILED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52935083/

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