Fix error caused by invalid charset in response headers#6123
Fix error caused by invalid charset in response headers#6123
Conversation
f541ffa to
7d2b7b9
Compare
|
Thanks for the PR, @deosrc! You've chosen an interesting time to raise this. We're currently working on options for typing in Requests and this was a case where there actually appears to be a bug in the code. Note that the response the server is giving you is not a valid response though and should be fixed on their end.
Which means the minimum viable We don't rely on value being boolean anywhere and there's no way to leave the function with the boolean and emit a successful request. The fix we'd proposed on the typing branch was to change the default. This will result in an empty |
Absolutley, this has been fixed. Your response all makes sense to me and sounds like it's fixed in the typing branch. I'll leave this up to you if you want to merge it in as an fix while the typing is ready, or for those unable to use typing. Happy for it to just be closed if it's not worth it as it's a rather obscure bug. |
Ran into an error where we were having an exception raised from the requests library:
'bool' object has no attribute 'strip'Seems the server was returning an empty charset value in the Content-Type response header of
application/json;charset. This was causing the line below to default the value to a booleanTrue:requests/requests/utils.py
Lines 524 to 529 in 2a6f290
This meant that attempting format the charset on the line below, the value was a boolean rather than a string:
requests/requests/utils.py
Lines 545 to 548 in 2a6f290
This change adds a type check so that the charset is ignored if a value is not provided. The unit test has been modified for coverage, along with expanding the other test scenarios slightly.