奇怪的错误响应 - 请求

时间:2017-04-09 19:39:07

标签: python python-3.x http-post

更新了代码 - 我使用此代码发送请求:

headers = {
"Host": "www.roblox.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US;q=0.7,en;q=0.3",
"Referer": "https://www.roblox.com/users/12345/profile",
"Content-Type": "application/json;charset=utf-8",
"X-CSRF-TOKEN": "some-xsrf-token",
"Content-Length": "27",
"DNT": "1",
"Connection": "close"
}
data = {"targetUserId":"56789"}
url = "http://www.roblox.com/user/follow"

r = requests.post(url, headers=headers, data=data, cookies={"name":"value"})

响应(使用r.text):

{"isValid":false,"data":null,"error":""}

请求本身是有效的,我使用burp发送它并且它有效:

POST /user/follow HTTP/1.1
Host: www.roblox.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: application/json, text/plain, */*
Accept-Language: pl,en-US;q=0.7,en;q=0.3
Referer: https://www.roblox.com/users/12345/profile
Content-Type: application/json;charset=utf-8
X-CSRF-TOKEN: Ab1/2cde3fGH
Content-Length: 27
Cookie: some-cookie=;
DNT: 1
Connection: close

{"targetUser":"56789"}

1 个答案:

答案 0 :(得分:0)

因为它在Burp中工作但在Python请求中不起作用,所以获取数据包嗅探器(Wireshark是最简单的IMO)并查看Burp发送的数据包的不同之处,以及从Python发送的不起作用的数据包。我怀疑问题是该网站是HTTPS,但您正在使用http://www.roblox.com。请尝试https://www.roblox.com,但我不确定它是否有用。