DigestAuthentication doesn't work with httpx

89 views Asked by At

It seems to be an issue with Digest Authentication when using httpx. Even with a basic HTTP server, I can't manage to correctly authenticate a client with httpx.

Here's the server implementation with Flask:

from flask import Flask
from flask_httpauth import HTTPDigestAuth

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret key here'
auth = HTTPDigestAuth()

users = {
    "john": "hello",
    "susan": "bye"
}


@auth.get_password
def get_pw(username):
    if username in users:
        return users.get(username)
    return None


@app.route('/', methods=['GET', 'POST'])
@auth.login_required
def index():
    return "Hello, {}!".format(auth.username())


if __name__ == '__main__':
    app.run(host="0.0.0.0", debug=True)

And here's the small client:

import httpx

auth = httpx.DigestAuth("susan", "bye")
print(httpx.get("http://192.168.2.140:5000/", auth=auth).status_code)

This code returns 401.

httpx version: 0.24.1

Does anyone has a solution ? I plan on using httpx to send asynchronous requests to a server with Digest Authentication. Only httpx seems to provide Digest Authentication with async support.

Many thanks

0

There are 0 answers