简体   繁体   English

Python3请求 - 不工作

[英]Python3 Requests - Not Working

I would like to submit a POST request using Python, preferably Python3. 我想使用Python提交POST请求,最好是Python3。 The problem is, the server must be blocking the request somehow (even with proper headers and cookies etc). 问题是,服务器必须以某种方式阻止请求(即使使用正确的标头和cookie等)。

To see for yourself, simply go to this link, fill out any phone number and email, and hit submit. 要亲眼看看,只需转到此链接,填写任何电话号码和电子邮件,然后点击提交。 I wish to replicate this, even if I need to use robobrowser or something (which won't work either). 我希望复制这个,即使我需要使用robobrowser或其他东西(也不会工作)。

https://sprint-locator.safely.com/signupBasicInformation.htm https://sprint-locator.safely.com/signupBasicInformation.htm

I have also tried replicating it with cURL, nothing. 我也试过用cURL复制它,什么都没有。

import requests

payload = {'email': 'admin%40dr.com', 'emailConfirm': 'admin%40dr.com', 'phoneNumber.areaCode': '302', 'phoneNumber.prefix': '750', 'phoneNumber.line': '1213'}
url='https://sprint-locator.safely.com/signupBasicInformation.htm'
r = requests.post(url, payload)
print(r.text)

Some sites require "proper" User-agent , for security reasons (sic!), to filter out bots (and more) allowing only browser clients. 有些网站需要“适当的” User-agent ,出于安全原因(原文如此!),过滤机器人(以及更多)仅允许浏览器客户端。

import requests

headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0'}
payload = {'email': 'admin%40dr.com', 'emailConfirm': 'admin%40dr.com', 'phoneNumber.areaCode': '302', 'phoneNumber.prefix': '750', 'phoneNumber.line': '1213'}
url='https://sprint-locator.safely.com/signupBasicInformation.htm'
r = requests.post(url, payload, headers=headers)
print(r.text)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM