Python 发送post请求:相同的请求,不同的行为?

Python 发送post请求:相同的请求,不同的行为?,python,post,Python,Post,我试图通过post请求远程触发网站上的操作 以下是我单击网站上的按钮时执行的请求示例: 以下是我发送的邮件: 我使用以下代码: import time import requests import json import urllib session = requests.session() login_data = { 'Username': #the mail here, 'Password': #the pass here, 'submit': 'login',

我试图通过post请求远程触发网站上的操作

以下是我单击网站上的按钮时执行的请求示例:

以下是我发送的邮件:

我使用以下代码:

import time
import requests
import json
import urllib

session = requests.session()
login_data = {
    'Username': #the mail here,
    'Password': #the pass here,
    'submit': 'login',
}
res = session.post(#[the url where I log in], data=login_data)


rep=session.get(#[the url from which I get the session s data]).text

#below I fetch some data I need in the post request
p=rep.find('id="__EVENTVALIDATION"')
eventval=rep[rep.find('value="',p)+len('value="'):rep.find('" />',p)]
p=rep.find('id="__VIEWSTATE"')
viewstate=rep[rep.find('value="',p)+len('value="'):rep.find('" />',p)]
p=rep.find('id="__VIEWSTATEGENERATOR"')
viewstategenerator=rep[rep.find('value="',p)+len('value="'):rep.find('" />',p)]

# parameters of the action
current_trade_currency="tx"
have="Robux" if current_trade_currency=="tx" else "Tickets"
want="Tickets" if current_trade_currency=="tx" else "Robux"
fromCur=10
toCur=100

tab={}
tab["__LASTFOCUS"]=""
tab["__EVENTTARGET"]="ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$SubmitTradeButton"
tab["__EVENTARGUMENT"]=""
tab["comments"]=""
tab["__VIEWSTATE"]=viewstate
tab["__EVENTVALIDATION"]=eventval
tab["__VIEWSTATEGENERATOR"]=viewstategenerator
tab["rdoNotifications"]="on"
tab["ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$OrderType"]="LimitOrderRadioButton"
tab["ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$HaveAmountTextBoxRestyle"]=str(fromCur)
tab["ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$HaveCurrencyDropDownList"]=str(have)
tab["ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$WantAmountTextBox"]=str(toCur)
tab["ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$WantCurrencyDropDownList"]=str(want)
tab["ctl00$ctl00$cphRoblox$cphMyRobloxContent$ctl00$AllowSplitTradesCheckBox"]="on"

headers={
    'Cache-Control': 'max-age=0',
    'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Origin' : 'http://www.roblox.com',
    'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.53 Safari/537.36',
    'Content-Type' : 'application/x-www-form-urlencoded',
    'Referer' : 'http://www.roblox.com/My/Money.aspx',
    'Accept-Encoding' : 'gzip, deflate',
    'Accept-Language' : 'en-US,en;q=0.8,fr;q=0.6'
}

session.post(#[the url where I perform the post request],data=tab).text.encode("utf-8"),headers=headers)
单击按钮时发送的post请求与我发送的post请求之间没有任何区别。然而,我的post请求不会触发任何事件

这是什么原因


编辑:以下是网站请求的一些特征的屏幕截图:

您是否也发送与浏览器相同的cookie?@MarkR。会话的使用应该能够处理这个问题。。正当在打印cookie时,除了少数无用的onesTry之外,大多数cookie似乎都得到了处理,并通过传递用户代理和接受标题假装成浏览器。如果服务器决定拒绝虚假请求,即使一切正常,您也无能为力。@MarkR。我添加了头文件={'User-Agent':Mozilla/5.0 X11;U;Linux i686 Gecko/20071127 Firefox/2.0.0.11,'Accept':'text/plain'},但它没有解决这个问题。