authlibflask-oauthlib

How can I send Authlib requests through a proxy?


With requests I can make a request through a proxy:

import requests
proxies = {
    "http": "http://proxy.yourorg.com:80",
    "https": "http://proxy.yourorg.com:80"
}
url = 'http://myorg.com/example'
response = requests.post(url, proxies=proxies)

Does Authlib provide a mechanism to use proxies for requests?

token = oauth.discord.authorize_access_token()
resp = oauth.discord.get('/users/@me')

Solution

  • Since Authlib is using requests, while requests support proxy through HTTP_PROXY environment variables, you can set:

    export HTTP_PROXY="http://proxy.yourorg.com:80"
    export HTTPS_PROXY="http://proxy.yourorg.com:80"
    

    While Authlib also support passing proxies into the parameters, try:

    token = oauth.discord.authorize_access_token(proxies=proxies)