MD Rijwan
MD Rijwan

Reputation: 481

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. But some HTTPSConnectionPool and Max Retries issues are coming.

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. 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. Header: Content Type: application/json and Authorization token given, and in body: The data in json. But Python Code for achieving the same doesn't work which is:

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')])")))"

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.

Upvotes: 0

Views: 10507

Answers (1)

kmaork
kmaork

Reputation: 6012

You could disable the SSL verification like you do in postman:

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.

Upvotes: 3

Related Questions