0

I am making a POST request to a URL using 'httpx' library. However, I get a 401 unauthorized error with my below request

cert = os.path.realpath('./certs/certificate.pem')
key = os.path.realpath('./certs/key.pem')
context = ssl.create_default_context()
context.load_cert_chain(certfile=cert, keyfile=key, password=os.getenv('PASSWORD', ''))
response = httpx.post(
            url=my_url,
            data={'client_id': os.getenv('USER', '')},
            verify=context
        )
token = response.json()['access_token']

In contrast, if I make the same request using 'requests' library, then it succeeds and I get the response. Below is my request

cert = os.path.realpath('./certs/certificate.pem')
key = os.path.realpath('./certs/key2.pem')
certificate = (cert, key)
response = requests.post(my_url, cert=certificate, auth=HTTPBasicAuth(os.getenv('USER', ''), os.getenv('PASSWORD', '')))
token = response.json()['access_token']

May I know what am I missing here?

Vishnukk
  • 524
  • 2
  • 11
  • 27
  • Your `httpx` request doesn't seem to be using HTTP Basic Auth, where the `requests` one does. See the httpx docs https://www.python-httpx.org/quickstart/#authentication – Anentropic Mar 13 '23 at 12:31

0 Answers0