Skip to content

Raising a HTTPUnauthorized caused error after upgrading from 3.6.2 to 3.7.4.post0 #5657

Closed
@teslafields

Description

🐞 Describe the bug

Raising a HTTPUnauthorized with a body="string" is giving an exception, as you can see in the traceback. This started to happen after I've upgraded from 3.6.2 to 3.7.4.post0. Looks to me that, as the body I return is str, it creates a StringPayload and still it tries to decode() it as it was bytes-like object

My piece of code that works in 3.6.2: raise web.HTTPUnauthorized(body='Not logged in')
Workaround to work in 3.7.4.post0: raise web.HTTPUnauthorized(body=b'Not logged in')

💡 To Reproduce

  1. Try to raise a HTTPUnauthorized with a string body

📋 Logs/tracebacks

Traceback (most recent call last):
  File "aiohttp/web_protocol.py", line 422, in _handle_request
  File "aiohttp/web_app.py", line 499, in _handle
  File "aiohttp/web_middlewares.py", line 119, in impl
  File "aiohttp_session/__init__.py", line 172, in factory
  File "aiohttp_session/__init__.py", line 154, in factory
  File "http_server.py", line 1869, in route_get_info
  File "http_server.py", line 461, in validate_identity
aiohttp.web_exceptions.HTTPUnauthorized: Unauthorized

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "aiohttp/web_protocol.py", line 485, in start
  File "aiohttp/web_protocol.py", line 427, in _handle_request
  File "aiohttp/web_response.py", line 650, in text
AttributeError: 'StringPayload' object has no attribute 'decode'

📋 Your version of the Python

$ python --version
Python 3.8.0

📋 Your version of the aiohttp/yarl/multidict distributions

aiohttp==3.7.4.post0
aiohttp-jinja2==1.4.2
aiohttp-security==0.4.0
aiohttp-session==2.9.0
multidict==5.1.0
yarl==1.6.3

Metadata

Assignees

No one assigned

    Labels

    bugregressionSomething that used to work stopped working "as before" after upgradereproducer: presentThis PR or issue contains code, which reproduce the problem described or clearly understandable STR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions