Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture python https traffic in fiddler?

Python throws in errors when ever I try to do some data fetching task. This only happens when I set fiddler to decrypt https traffic. I have tried routing python traffic through 127.0.0.1:8888 and same with mozilla inorder to catch its traffic. I also installed the certificate and trusted it via fiddler, I am not sure where I am going wrong.

    raise SSLError(e, request=request)
    requests.exceptions.SSLError: HTTPSConnectionPool(host='google.com', port=443):
    Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFIC
    ATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),))

This above is the error I get whenever I try to fetch a page with requests.

like image 439
rikoudosenin Avatar asked Sep 30 '17 13:09

rikoudosenin


1 Answers

TL;DR The requests library does not use the windows certificate store, it has it's own one (as per https://bugs.python.org/issue28547). This means that your fiddler MITM certificate is not available to python requests by default.

Your options are

  1. Disable SSL verification (verify=False)
  2. Add your cert via the REQUESTS_CA_BUNDLE environment variable
  3. Add your fiddler cert explicitly (verify='\path\to\cert')

More details can be found at http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification

On a side note, it does feel a little strange for requests to be using it's own cert bundle, rather than the platform supplied one - especially given all the browsers are happy to use the platform ones.

like image 125
polhemic Avatar answered Nov 15 '22 00:11

polhemic