Search code examples
python-requestsssl-certificatehttp-post

How can I fix the following error while using certificate on request?


I am getting the following error while using certificate in requests to post data to a website.

It works fine when I set verify = false.

Error:- requests.exceptions.SSLError: HTTPSConnectionPool(host='www.example.com', port=443): Max retries exceeded with url: /login (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))


Solution

  • You can disable it using the urllib module.

    import requests
    import urllib3
    from urllib3.exceptions import InsecureRequestWarning
    urllib3.disable_warnings(InsecureRequestWarning)
    
    res = requests.get('https://example.com',verify=False)