-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Raising a HTTPUnauthorized caused error after upgrading from 3.6.2 to 3.7.4.post0 #5657
Comments
Sounds like a regression. The first step towards addressing this would be adding a regression test marked as xfail per https://pganssle-talks.github.io/xfail-lightning/. The PR should be sent against master and it can be merged with that xfail marker. |
Looks like the change here UPD: link is not right, it was introduced earlier. I will continue to search a little bit later. Here's reproducer: from aiohttp import web
routes = web.RouteTableDef()
@routes.get('/', name='main')
async def hello(request):
raise web.HTTPUnauthorized(body='Not logged in')
app = web.Application()
app.add_routes(routes)
web.run_app(app, port=8082) Works in 3.6.3, does not work in 3.7.0 |
@paulefoe it's best to submit that as a regression test marked as xfail pointing to this issue in the "reason=" arg per https://pganssle-talks.github.io/xfail-lightning/ |
Alright, with a regression test in place, it's time to have this compatibility issue addressed. |
I will be looking into it tomorrow |
I think I found it, it's this change: In both 3.6.3 and 3.7.0 StringPayload, however, is fairly easy to decode, we can do something like: @property
def text(self) -> Optional[str]:
if self._body is None:
return None
if isinstance(self._body, StringPayload):
return self._body._value.decode(self._body.encoding)
return self._body.decode(self.charset or "utf-8") Although, then we should probably make |
🐞 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
📋 Logs/tracebacks
📋 Your version of the Python
📋 Your version of the aiohttp/yarl/multidict distributions
The text was updated successfully, but these errors were encountered: