我使用Python 2.7.7發送一個post請求到一個網站。使用請求模塊和我的代碼林看起來是這樣的:(NAME和PASS被取代)Python - POST請求repsonse和JSON解析
r = requests.post("http://play.pokemonshowdown.com/action.php", data="act=login&name=NAME&pass=PASS&challengekeyid="+challstrarr[2]+"&challenge="+challstrarr[3])
print(r.text)
print(r.json())
r.text只返回一個空行,r.Json返回此錯誤:「ValueError異常:無JSON對象可以是解碼」
網站i'm請求具有以下教程:
you'll need to make an HTTP POST request to http://play.pokemonshowdown.com/action.php with the data act=login&name=USERNAME&pass=PASSWORD&challengekeyid=KEYID&challenge=CHALLENGE
Either way, the response will start with ] and be followed by a JSON object which we'll call data."
我不確定是否發佈請求的響應是錯誤的(因此空行),或者如果沒有故障的json解析關閉
當你與捲曲嘗試會發生什麼? –
我會確保'challstrarr [2]'和'challstrarr [3]'是你想象的那樣並且打印出數據來看看它的樣子 –
它適用於curl,我得到json文件的內容,但我仍然與r.text空行。 我沒有檢查數組的指標,我打印出來,它的所有正確 – user3710165