I have a docker image flask web application which is generating the error below after rebuilding the docker image and deploying the docker container from it.
Before today, the containers from the images built using the docker file and requirements.txt file as this image ran without any errors.
I suspect there may have been a recent python module update in the image I built today that is causing the error below.
The Python version is Python 3.12.0
The output of pip list is shown below.
root@8015f43d01aa:/# pip list
Package Version
------------------ ---------
blinker 1.6.2
cachelib 0.10.2
certifi 2023.7.22
charset-normalizer 3.3.0
click 8.1.7
Flask 2.3.3
Flask-PyMongo 2.3.0
Flask-Session 0.5.0
gunicorn 21.2.0
idna 3.4
itsdangerous 2.1.2
Jinja2 3.1.2
MarkupSafe 2.1.3
packaging 23.2
pika 1.3.2
pip 23.2.1
psycopg2 2.9.8
pyasn1 0.5.0
pyasn1-modules 0.3.0
pymongo 3.12.3
python-dateutil 2.8.2
python-ldap 3.4.3
redis 5.0.1
requests 2.31.0
setuptools 68.2.2
six 1.16.0
urllib3 2.0.6
Werkzeug 3.0.0
wheel 0.41.2
The error message.
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1487, in full_dispatch_request
return self.finalize_request(rv)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 1508, in finalize_request
response = self.process_response(response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/flask/app.py", line 2005, in process_response
self.session_interface.save_session(self, ctx.session, response)
File "/usr/local/lib/python3.12/site-packages/flask_session/sessions.py", line 454, in save_session
response.set_cookie(app.config["SESSION_COOKIE_NAME"], session_id,
File "/usr/local/lib/python3.12/site-packages/werkzeug/sansio/response.py", line 224, in set_cookie
dump_cookie(
File "/usr/local/lib/python3.12/site-packages/werkzeug/http.py", line 1303, in dump_cookie
if not _cookie_no_quote_re.fullmatch(value):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot use a string pattern on a bytes-like object
Downgrading to Werkzeug==2.3.7 from Werkzeug==3.0.0 solved the above error.
Werkzeug==3.0.0 was released 2023-September-30.
2
Answers
Downgrading to Werkzeug==2.3.7 from Werkzeug==3.0.0 solved the above error. Werkzeug==3.0.0 was released 2023-September-30.
Make sure that the cookie value that is passed to
set_cookie()
is cast to string. Byte-like objects would previously work but cause this error in the latest Werkzeug version.