簡體   English   中英

用於 oauth 令牌的 Python 請求庫

[英]Python requests library for oauth token

因此,我按照從https://developer.spotify.com/documentation/general/guides/authorization/client-credentials/獲取 OAUTH 令牌的指南進行操作,我嘗試使用上述等效代碼的 python 請求庫,但我得到了響應400 來自服務器。 我可以知道我哪里出錯了嗎?

import requests
import json
import clientidandsecret


headers ={"Authorization": "Basic " + clientidandsecret.C_ID +":" +clientidandsecret.C_SECRET}
form = {"form":{"grant_type" :"client_credentials"}, "json":"true"}
result = requests.post("https://accounts.spotify.com/api/token", headers=headers, data=form)
print(result)

您的變量形式是一個字典,如果您想在請求中使用參數數據,它需要是一個字符串,這將解決它:

import json
...
result = requests.post(url, headers=headers, data=json.dumps(form))

甚至更好:

result = requests.post(url, headers=headers, json=form)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM