requests-oauthlib
requests-oauthlib copied to clipboard
Confusing handling of unexpected server response in fetch_token
I am using fetch_token with the standard web client, but the server I am talking to returns a non-standard response (its just a text string saying 403/ bad auth ...).
The error I see is a MissingTokenError, rather than something more explanatory. This left me chasing my tail since I thought there was something wrong with the response, etc.
Ideas:
- In the 403 case, re-raise that as an explicit error
- In the "unexpected body" or "bad format", raise a
BadResponseErroror similar - Add status_code/resp.text to the exception as well, to help with debugging
Another user experiences the same issue at https://github.com/oauthlib/oauthlib/issues/510. A status check must be added at https://github.com/requests/requests-oauthlib/blob/master/requests_oauthlib/oauth2_session.py#L232-L244