如何通过代理发送 Authlib 请求?

How can I send Authlib requests 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)

Authlib 是否提供使用代理请求的机制?

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

由于Authlib使用的是requests,而requests支持通过HTTP_PROXY环境变量进行代理,您可以设置:

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

虽然 Authlib 也支持将 proxies 传递到参数中,请尝试:

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