简体   繁体   English

使用请求模块在Python中的Http Post请求中超出了最大重试次数并且证书验证失败

[英]Max retries exceeded and Certificate Verify Failed in Http Post Request in Python using requests Module

I am sending a POST Http request through requests module in Python. 我通过Python中的请求模块发送POST Http请求。 But some HTTPSConnectionPool and Max Retries issues are coming. 但是一些HTTPSConnectionPool和Max Retries问题即将到来。

I have tried many solutions which i found in other platforms like updating pyOpenSSL library, Using exception handling of connection error, Giving some sleep time like about 5 seconds.But nothing solving my problem. 我尝试了很多解决方案,我在其他平台上找到了,比如更新pyOpenSSL库,使用连接错误的异常处理,给大约5秒的休眠时间。但没有解决我的问题。 Still getting Error message like Connection issues, maximum retries failed and certificate verify failed. 仍然收到错误消息,如连接问题,最大重试失败和证书验证失败。 In PostMan same POST url is working perfectly, Authorization Type : No Auth. 在PostMan中,相同的POST URL工作正常,授权类型:No Auth。 Header: Content Type: application/json and Authorization token given, and in body: The data in json. 标题:内容类型:给定的application / json和授权令牌,以及正文:json中的数据。 But Python Code for achieving the same doesn't work which is: 但实现相同的Python代码不起作用,这是:

import requests
import time

url_api = "POST Url"

header = { 
"Content-Type": "application/json", 
"Authorization": "AutheticationIDXYZ" 
}
payload ={
            "name": "python1236",
            "description": "python1236"
           }

r = requests.post(url = url_api, data = payload,json = header)
time.sleep(3)
r.raise_for_status() 
print(r.status_code,r.reason)

The expected result is that it should return the json response but showing error "TTPSConnectionPool(host='api.com', port=443): Max retries exceeded with url: /api/v1/projects (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))" 预期的结果是它应该返回json响应,但显示错误“TTPSConnectionPool(host ='api.com',port = 443):url:/ api / v1 / projects超出了最大重试次数(由SSLError引起(SSLError(”坏握手:错误([('SSL例程','tls_process_server_certificate','证书验证失败')])“)))”

Is there anything wrong in my code or in my approach. 我的代码或方法中是否有任何错误。 I am new to Python API framework so can Flask solve my issue in any case.Any suggestion and help will be appreciated, Thanks. 我是Python API框架的新手,所以Flask在任何情况下都可以解决我的问题。任何建议和帮助将不胜感激,谢谢。

You could disable the SSL verification like you do in postman: 您可以像邮递员一样禁用SSL验证:

r = requests.post(url = url_api, data = payload,json = header, verify = False)

Although this might be dangerous and surely shouldn't be used in production code. 虽然这可能很危险,但肯定不应该在生产代码中使用。 To avoid that, consider installing the API's certificate. 为避免这种情况,请考虑安装API证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM