Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1854

SSL: CERTIFICATE_VERIFY_FAILED error for httpx but works for requests

$
0
0

I am switching over some code originally hitting an API through http to now use https. The code is using httpx to hit the API. When trying to make a request I am getting

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for

The code basically looks like this:

import httpx import json creds = {'username': '123', 'password': '456'} headers = {'Content-Type': 'application/json'} client = httpx.Client(base_url=base_url, headers=headers)params = json.dumps(creds)resp = client.post('/login', data=params)

The strange thing is when I try the same thing using requests it works perfectly fine

import requestsrequests.post(f"{base_url}/login", data=params, headers=headers)

I thought the issue might be that requests is somehow choosing to bypass ssl verification by default but even when I explicitly pass verify=True to the post it still works. Any ideas on the discrepancy between the two packages and how to fix this issue would be greatly appreciated.

It's not my codebase and it uses async calls so I can't just switch over to using requests.

Note: I am on macOS


Viewing all articles
Browse latest Browse all 1854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>