Python请求发布被服务器阻止

标签 python python-requests

我正在尝试使用我的用户名和密码登录网站,转到报告页面,选择条件并下载报告。我正在尝试使用请求来自动执行此操作。

到目前为止我已经:

report_page_url = 'http://url......'
signin = {username, password}
data = {
     'from_day': '1',
     'from_month': '3',
     'from_year': '2016'}

 with requests.Session() as s:
     s.post(login_url, data=signin)
     download = s.post(report_page_url, data=data)

我可以登录第一篇文章的站点,并下载报告页面的页面内容。

但是,每次我在报告页面上执行 requests.post 并传入参数来填写表单时,它都会将我重定向到带有错误消息的页面:

You are attempting to modify settings from a URL that does not appear to have come from a FreePBX page link or button. This can occur if you manually typed in the URL below. This action has been blocked because the HTTP_REFERER does not match your current SERVER. If you require this access, you can set Check Server Referrer=false in Advanced Settings to disable this security check.

有什么办法可以绕过它吗?

谢谢!

最佳答案

听起来他们实际上是在检查 HTTP_REFERER 并拒绝来自国外的帖子。尝试在请求中添加 http_referer header ,例如:

s.headers.update({'referer': my_referer})

您需要弄清楚他们希望在 my_referer 中看到什么值(value)。可能只是他们自己的域名。

关于Python请求发布被服务器阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35785396/

相关文章:

python - 从网站上抓取动态变化图像的 URL

python - ValueError:无法将国家/类别参数与来源参数混合

python - 如何使用带有 Pandas 数据帧的请求来创建多个 Get http 请求?

ssl - 当 HTTPS 站点使用 "ISRG Root X1"CA 时,Python3.4+requests 2.26 无法验证 SSL 证书 - 为什么?

Python 请求.exceptions.SSLError : EOF occurred in violation of protocol

python - 比较简单的 Python ctypes 数据类型

python - wxpython balloonframe覆盖所有窗口

python - 在 Python 中创建 LazilyEvaluatedConstantProperty 类

python - 如果它们具有相同列的值,如何更新 pandas 列?

python - 自签名证书私钥值不匹配