【问题标题】:How to avoid invalid inputs error while passing form data in python requests?在 python 请求中传递表单数据时如何避免无效输入错误?
【发布时间】:2019-09-29 20:39:30
【问题描述】:

我正在使用 Python 2.7 向 billdesk 网站发送帖子请求,并附上我的客户编号以获取其详细信息。

我在传递以下请求时收到无效输入错误。 我也尝试过使用 json 编码的表单数据。

url="https://pgi.billdesk.com/pgidsk/pgmerc/rvvnlaj/RVVNLAJConfirm.jsp"

payload={
        "service":"BILL",
        "txtCustomerID":"110331033880",
        "txtEmail":"mymailid@gmail.com"
        }

headers={
       "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
       "Accept-Encoding":"gzip, deflate, br",
       "Accept-Language": "en-US,en;q=0.9",
       "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
       "Upgrade-Insecure-Requests": "1",
       "Content-Type":"application/x-www-form-urlencoded",
       "Connection":"keep-alive",
       "Host":"pgi.billdesk.com"
   }

z=requests.post(url,headers=headers,data=payload)
print z.content

我希望内容中包含帐单详细信息,但我收到无效输入错误。

<td >&nbsp;</td>
<td bgcolor="#ff9966" class="textrvvnl">Invalid Inputs</td>
<td >&nbsp;</td>
</tr>
<tr>
<td >&nbsp;</td>
<td bgcolor="#ff9966" class="textrvvnl">&nbsp;
</td>
<td >&nbsp;</td>
</tr>

请告知我是否以不正确的格式传递表单数据。

【问题讨论】:

    标签: python json python-2.7 web-scraping python-requests


    【解决方案1】:

    您使用了错误的标题,请尝试使用这些标题:

    headers={
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:66.0) Gecko/20100101 Firefox/66.0",
            "Referer": "https://pgi.billdesk.com/pgidsk/pgmerc/rvvnlaj/RVVNLAJDetails.jsp"
           }
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2015-09-04
      • 2017-07-22
      • 2015-03-18
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      相关资源
      最近更新 更多