Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: cannot use a string pattern on a bytes-like object #292

Closed
mmreza79 opened this issue Nov 13, 2023 · 1 comment
Closed

TypeError: cannot use a string pattern on a bytes-like object #292

mmreza79 opened this issue Nov 13, 2023 · 1 comment

Comments

@mmreza79
Copy link

I am having trouble storing flask session with werkzeug v.3.0.1. My production code was working fine till update the latest version. Now, I am encounter the following problem.

[ERROR] Error in ASGI Framework
Traceback (most recent call last):
  File ".../lib/python3.11/site-packages/hypercorn/asyncio/task_group.py", line 27, in _handle
    await app(scope, receive, send, sync_spawn, call_soon)
  File ".../lib/python3.11/site-packages/hypercorn/app_wrappers.py", line 33, in __call__
    await self.app(scope, receive, send)
  File ".../lib/python3.11/site-packages/quart/app.py", line 1621, in __call__
    await self.asgi_app(scope, receive, send)
  File ".../lib/python3.11/site-packages/quart/app.py", line 1647, in asgi_app
    await asgi_handler(receive, send)
  File ".../lib/python3.11/site-packages/quart/asgi.py", line 52, in __call__
    raise_task_exceptions(done)
  File ".../lib/python3.11/site-packages/quart/utils.py", line 187, in raise_task_exceptions
    raise task.exception()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/tasks.py", line 267, in __step
    result = coro.send(None)
             ^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/quart/asgi.py", line 100, in handle_request
    response = await _handle_exception(self.app, error)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/quart/asgi.py", line 357, in _handle_exception
    raise error
  File ".../lib/python3.11/site-packages/quart/asgi.py", line 98, in handle_request
    response = await self.app.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/quart/app.py", line 1363, in handle_request
    return await self.handle_exception(error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/quart/app.py", line 1359, in handle_request
    return await self.full_dispatch_request(request_context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/quart_flask_patch/app.py", line 28, in new_full_dispatch_request
    return await old_full_dispatch_request(self, request_context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/quart/app.py", line 1398, in full_dispatch_request
    return await self.finalize_request(result, request_context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/quart/app.py", line 1522, in finalize_request
    response = await self.process_response(response, request_context)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/quart/app.py", line 1583, in process_response
    await self.ensure_async(self.session_interface.save_session)(self, session_, response)
  File ".../lib/python3.11/site-packages/quart_flask_patch/app.py", line 43, in _wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/flask_session/sessions.py", line 362, in save_session
    response.set_cookie(app.config["SESSION_COOKIE_NAME"], session_id,
  File ".../lib/python3.11/site-packages/werkzeug/sansio/response.py", line 224, in set_cookie
    dump_cookie(
  File ".../lib/python3.11/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

Environment:

  • Python version: 3.11
  • Werkzeug version: 3.0.1
  • Quart version: 0.19.3
  • Flask-Session version: 0.5.0

Can anybody help me resolving the issue?

@davidism davidism transferred this issue from pallets/werkzeug Nov 21, 2023
@pgjones
Copy link
Member

pgjones commented Nov 26, 2023

This is an issue with Flask-Session, which needs an upgrade to be compatible with Werkzeug >= 3. Try rolling back to Quart 0.18 and Werkzeug < 3.

@pgjones pgjones closed this as completed Nov 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants