Python POST请求repsonse和JSON解析

2024-10-05 10:07:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Python2.7.7向网站发送post请求。Im使用requests模块,代码如下:(NAME和PASS被替换)

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())

Json返回的是一个空的Json对象,错误是:一个错误

我请求的网站有以下教程:

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."

我不确定POST请求响应是否是错误的(因此是空白行),或者如果它没有错误,JSON解析是关闭


Tags: namecomhttpplaydata网站错误login
1条回答
网友
1楼 · 发布于 2024-10-05 10:07:14

您应该将dictionary对象传递给post函数(data参数),只有在get方法中才应该传递查询字符串:

postData = {
#put you post data here
}
r = requests.post("http://play.pokemonshowdown.com/action.php", data=postData)
print(r.text)
print(r.json())

相关问题 更多 >

    热门问题