我正在使用requests-oauthlib
来使用ETrade API进行身份验证。它需要授权的URL具有以下格式:使用请求修改授权URL格式-oauthlib
https://us.etrade.com/e/t/etws/authorize?key={oauth_consumer_key}&token={oauth_token}
然而,当我打电话authorization_url()
,它使用oauth_token
,而不是token
该参数。目前我使用format()
来自己格式化URL,但现在我有token
和oauth_token
参数。这有效,但完全不雅。有没有办法修改authorization_url()
的行为以允许我需要的URL格式?
为了完整起见,这里是我的代码:
oauth_session = requests_oauthlib.OAuth1Session(config.oauth_consumer_key, config.consumer_secret, callback_uri='oob')
def get_request_token():
path = 'oauth/request_token'
url = base_url + path
return oauth_session.fetch_request_token(url)
def get_authorization_url(request_token):
url_format = 'https://us.etrade.com/e/t/etws/authorize?key={oauth_consumer_key}&token={oauth_token}'
url = url_format.format(oauth_consumer_key=config.oauth_consumer_key, oauth_token=request_token['oauth_token'])
return oauth_session.authorization_url(url)
request_token = get_request_token()
print(get_authorization_url(request_token))
据我所知道的,额外的'的oauth_token '参数不会导致任何问题。 'authorization_url()'提供了什么额外的安全性?它是否对令牌进行URL编码?还要别的吗? –