2016-08-18 129 views
0

我簡直無法得到這個工作。使用請求發佈到pastebin API

header = {"Content-Type": "application/json; charset=utf8"} 
params = {"api_dev_key": dev_key, "api_user_name": username, "api_user_password": password} 
req = requests.post("http://pastebin.com/api/api_login.php", params = json.dumps(params), headers = header) 
print(req.status_code, req.reason, req.text) 

變量(我的憑據)只是字符串。 響應我得到:

(200, 'OK',u'Bad API請求,無效api_dev_key')

有沒有錯鍵,這個帖子的時候我用https://www.hurl.it工作正常

回答

1

您需要直接使用數據=參數

req = requests.post("http://pastebin.com/api/api_login.php", data=params)