From 74934e68d53f9a842925cbe8d2756fd9f4ac0da0 Mon Sep 17 00:00:00 2001 From: Danila Balagansky Date: Mon, 6 Nov 2023 15:45:12 +0300 Subject: [PATCH] Add simultaneous support for Werkzeug 2 and 3 This is the follow-up for PR #1356. (cherry picked from commit 860c82bdd656ddd7adbc3111f8aeefef21ee92e4) --- gnocchi/rest/auth_helper.py | 7 ++++++- setup.cfg | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gnocchi/rest/auth_helper.py b/gnocchi/rest/auth_helper.py index d11fadf1b..d5df68939 100644 --- a/gnocchi/rest/auth_helper.py +++ b/gnocchi/rest/auth_helper.py @@ -121,7 +121,12 @@ def get_current_user(request): hdr = request.headers.get("Authorization") auth_hdr = (hdr.decode('utf-8') if isinstance(hdr, bytes) else hdr) - auth = werkzeug.http.parse_authorization_header(auth_hdr) + + try: + auth = werkzeug.http.parse_authorization_header(auth_hdr) + except AttributeError: + auth = werkzeug.datastructures.Authorization.from_header(auth_hdr) + if auth is None: api.abort(401) return auth.username diff --git a/setup.cfg b/setup.cfg index 41ed981f2..82cdfaf41 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,7 +42,7 @@ install_requires = stevedore ujson voluptuous>=0.8.10 - werkzeug<3.0.0 + werkzeug trollius; python_version < '3.4' tenacity>=5.0.0 WebOb>=1.4.1