0

requests_oauthlib を使用して Listrak API から有効な応答を取得しようとしていますが、取得できるのは無効な資格情報だけです。キーをリセットしようとしましたが、同じ問題です。コードは次のとおりです。<> セクションはコード内の実際のキーに置き換えられます。

#Imports
import requests
import requests_oauthlib
from oauthlib.oauth2 import BackendApplicationClient

#Keys
id = <client_id>
secret = <client_secret>
#Token URL
token_url = 'https://auth.listrak.com/OAuth2/Token'

#Auth Request
client = BackendApplicationClient(client_id=id)
oauth = requests_oauthlib.OAuth2Session(client=client)
token = oauth.fetch_token(
    token_url=token_url, client_id=id, client_secret=secret)

デバッグ ログ:

2019-12-09 13:31:27,014 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Encoding `client_id` "<client_id>" with `client_secret` as Basic auth credentials.
2019-12-09 13:31:27,014 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Requesting url https://auth.listrak.com/OAuth2/Token using method POST.
2019-12-09 13:31:27,014 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Supplying headers {'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'} and data {'grant_type': 'client_credentials'}
2019-12-09 13:31:27,014 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Passing through key word arguments {'timeout': None, 'auth': <requests.auth.HTTPBasicAuth object at 0x03EBC5F8>, 'verify': True, 'proxies': None}.
2019-12-09 13:31:27,014 - urllib3.connectionpool - DEBUG - 4396 - Starting new HTTPS connection (1): auth.listrak.com:443
2019-12-09 13:31:27,217 - urllib3.connectionpool - DEBUG - 4396 - https://auth.listrak.com:443 "POST /OAuth2/Token HTTP/1.1" 400 31
2019-12-09 13:31:27,217 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Request to fetch token completed with status 400.
2019-12-09 13:31:27,217 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Request url was https://auth.listrak.com/OAuth2/Token
2019-12-09 13:31:27,217 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Request headers were {'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Content-Length': '29', 'Authorization': 'Basic emludWp1YnEzczdibHc4dmRrMDY6SGgwQWIyZkJZWWcvLzVZMTF1M1djWGpZWFpLWWpzVFNxTW83ckNteDBScw=='}
2019-12-09 13:31:27,217 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Request body was grant_type=client_credentials
2019-12-09 13:31:27,217 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Response headers were {'Server': 'Microsoft-IIS/8.5', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json;charset=UTF-8', 'Date': 'Mon, 09 Dec 2019 19:31:26 GMT', 'Expires': '-1', 'Pragma': 'no-cache', 'Connection': 'close', 'X-Powered-By': 'ASP.NET', 'Content-Length': '31'} and content {"error":"Invalid Credentials"}.
2019-12-09 13:31:27,217 - requests_oauthlib.oauth2_session - DEBUG - 4396 - Invoking 0 token response hooks.

4 行目で、"auth" 引数が次のよう'auth': <requests.auth.HTTPBasicAuth object at 0x03EBC5F8>になっていることに気付きました。それはいくつかの値を持つべきだと思われますか?どんなアドバイスでも大歓迎です。

4

1 に答える 1