Python 在im使用请求发布数据时收到错误的请求

Python 在im使用请求发布数据时收到错误的请求,python,post,python-requests,steam,bad-request,Python,Post,Python Requests,Steam,Bad Request,当我试图将数据发布到steam时,我总是收到错误消息“请求错误”,我做了很多重新研究,我不知道如何解决这个问题 职位价值: # Post Values total = int(item['price']) fee = int(item['fee']) subtotal = total-fee 曲奇饼: # Cookies c = [] c.append('steamMachineAuthXXXXXXXXXXXXXXXXX='+steamMachineAuth) c.append('st

当我试图将数据发布到steam时,我总是收到错误消息“请求错误”,我做了很多重新研究,我不知道如何解决这个问题

职位价值:

# 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
}
网址:

发送请求:

# Sending Request
se = requests.Session()
re = se.post(url, data=post, headers=headers)
print re.reason
输出:
错误请求

我无法具体介绍Steam服务,因为我还没有使用它,但我对典型错误请求响应的经验是,您尝试的HTTP动词不受支持,或者您的请求格式不正确

就你而言,我怀疑是后者

我首先要看的是你的cookie格式。您确定没有需要转义的字符吗

我可以建议使用类似这样的方式:

c = { 
    'steamMachineAuthXXXXXXXXXXXXXXXXX': steamMachineAuth,
    'steamLogin': steamLogin,
    'steamLoginSecure': steamLoginSecure,
    'sessionid': sessionid
}
cookie = '; ',join('{}="{}"'.format(k, v) for k, v in c.items())

我尝试了许多可能的方法来发送cookie、标题和post数据,所以我认为这是一个不同的问题。也许有些数据丢失了。
c = { 
    'steamMachineAuthXXXXXXXXXXXXXXXXX': steamMachineAuth,
    'steamLogin': steamLogin,
    'steamLoginSecure': steamLoginSecure,
    'sessionid': sessionid
}
cookie = '; ',join('{}="{}"'.format(k, v) for k, v in c.items())