1

I am using requests package in Python to call some APIs. I am behind a corporate firewall, so I was using proxies to access data from the APIs. But now I need to use OAuth2 as well. Requests does not support OAuth2 by itself, we have to use requests-oauthlib for that. But requests-oauthlib does not have option to use proxies (see its documentation here).

So, how can I use both OAuth2 and proxies? Although I prefer to use requests package for its simplicity, any method is welcome.

2 Answers 2

5

The session objects provided by requests-oauthlib inherit from requests.Session, so you can specify proxies on them the same way that you can on an instantiated requests.Session():

from requests_oauthlib import OAuth2Session

session = OAuth2Session(...)
session.proxies = {'all': 'http://my.proxy.url:3128'}

session.fetch_token(...)
Sign up to request clarification or add additional context in comments.

Comments

0

I suggest either modify the requests-oauthlib for your purpose to support Proxy or directly use requests API as writing oauth clients is not that difficult. It is same standard HTTP stuff

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.