当我试图将数据发布到Steam时,我总是收到错误消息“Bad Request”,我做了很多研究,我不知道如何解决这个问题。
发布值:
# Post Values
total = int(item['price'])
fee = int(item['fee'])
subtotal = total-fee
饼干:
# Cookies
c = []
c.append('steamMachineAuthXXXXXXXXXXXXXXXXX='+steamMachineAuth)
c.append('steamLogin='+steamLogin)
c.append('steamLoginSecure='+steamLoginSecure)
c.append('sessionid='+sessionid)
cookie = ''
for value in c:
cookie = cookie+''+value+'; '
接头:
# Headers
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4",
"Connection": "keep-alive",
"Host": "steamcommunity.com",
"Referer": hosturl+"market/listings/"+appid+"/"+item['market_hash_name'],
"Cookie": cookie,
"Origin": hosturl,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36",
"X-Requested-With": "XMLHttpRequest"
}
发布数据:
# Post Data
post = {
'sessionid': sessionid,
'currency': int(currency),
'subtotal': subtotal,
'fee': fee,
'total': total,
'quantity': 1
}
地址:
# url
url = hosturl+'market/buylisting/'+item['listingid']
发送请求:
# Sending Request
se = requests.Session()
re = se.post(url, data=post, headers=headers)
print re.reason
输出: 错误的要求
答案 0 :(得分:0)
我不能专门谈论Steam服务,因为我还没有使用它,但我对典型的错误请求响应的经验是你要么尝试一个非动词的HTTP动词t支持或您的请求格式不正确。
在你的情况下,我怀疑是后者。
我要看的第一个候选人是你的cookie格式。你确定你没有需要转义的角色吗?
我建议改用这样的东西:
c = {
'steamMachineAuthXXXXXXXXXXXXXXXXX': steamMachineAuth,
'steamLogin': steamLogin,
'steamLoginSecure': steamLoginSecure,
'sessionid': sessionid
}
cookie = '; ',join('{}="{}"'.format(k, v) for k, v in c.items())