You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes proper reason is missing in the Error thrown by the raise_for_status method.
Exception has occurred: HTTPError 405 Client Error: for url: https://bla.com
This is becasue the reason is an empty string on #Line1010
But it would be helpful to maybe try and deduct a reason, if not provided by the server (i.e. just a status code is provided)
My very ugly implementation of this would look like (just before Line1010)
from http import HTTPStatus # somewhere on top
....
if not reason:
for msg, code in HTTPStatus.__dict__.items():
if code == self.status_code:
reason = msg
break
I am sure you guys will find a one liner.
I would expect a more clear error message as follows
Exception has occurred: HTTPError 405 Client Error: METHOD_NOT_ALLOWED for url: https://bla.com
Reproduction Steps
Simply try sending a POST message to a server that does not accept POST.
The server should return a proper status_code back but the reason should/could be empty.
This might not be an edge case and can be see in some popular servers (eg. I saw this in Jira REST API).
Hey @gk-patel, I can see the reason in response for the method not allowed for jira rest api as well. Check the screenshot attached. Else can you give more brief on steps to reproduce
Maybe its a problem with our enterprise Jira, unfortunately it does not return r.reason.
The sample error message I printed above was a real example from our enterprise Jira.
I am just suggesting a fall back improvement. I dont think it should interfere with currently available behavior.
Hi @gk-patel, we generally won't try to infer what a server is intending or mutate what we've received. Reasons are optional metadata from the server and allowed to be omitted. What each status codes means is widely published. If a user needs a textual reminder, it should be quick to look up from the codes list as you've shown.
I think we'll close this as I don't see it being an accepted feature. Thanks for the suggestion.
Sometimes proper reason is missing in the Error thrown by the raise_for_status method.
Exception has occurred: HTTPError 405 Client Error: for url: https://bla.com
This is becasue the
reason
is an empty string on #Line1010But it would be helpful to maybe try and deduct a reason, if not provided by the server (i.e. just a status code is provided)
My very ugly implementation of this would look like (just before Line1010)
I am sure you guys will find a one liner.
I would expect a more clear error message as follows
Exception has occurred: HTTPError 405 Client Error: METHOD_NOT_ALLOWED for url: https://bla.com
Reproduction Steps
Simply try sending a POST message to a server that does not accept POST.
The server should return a proper status_code back but the reason should/could be empty.
This might not be an edge case and can be see in some popular servers (eg. I saw this in Jira REST API).
System Information
The text was updated successfully, but these errors were encountered: