且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

奇怪的错误响应-请求

更新时间:2022-10-16 11:53:35

由于它可以在Burp中工作,但不能在Python请求中工作,因此请获取一个数据包嗅探器(Wireshark是最简单的IMO),然后查看一下发送的数据包中的区别打p有效,而从Python发送的打p无效.我怀疑问题在于该网站是HTTPS,但您使用的是 http://www.roblox.com .尝试尝试 https://www.roblox.com ,但我不确定是否可以使用.>

Updated code - I'm using this code to send the request:

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"})

Response (using r.text):

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

The request itself is valid, I sent it using burp and it worked:

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

Because it works in Burp but not in Python requests, get a packet sniffer (Wireshark is the simplest IMO) and look to see the difference in the packet sent by Burp that works and the one sent from Python that does not work. I am suspecting that the problem is that the website is HTTPS but you are using http://www.roblox.com . Do try https://www.roblox.com , but I am not sure if it will work.