requests-oauthlib icon indicating copy to clipboard operation
requests-oauthlib copied to clipboard

Confusing handling of unexpected server response in fetch_token

Open awbacker opened this issue 7 years ago • 1 comments

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 BadResponseError or similar
  • Add status_code/resp.text to the exception as well, to help with debugging

awbacker avatar Jan 04 '18 08:01 awbacker

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

JonathanHuot avatar Jan 29 '18 09:01 JonathanHuot