我正在尝试使用我的用户名和密码登录网站,转到报告页面,选择条件并下载报告。我正在尝试使用请求来自动执行此操作。
到目前为止我已经:
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/