viviwill
viviwill

Reputation: 1573

Python requests post blocked by server

I'm trying to login a site with my username and password, go to the report page, select the criteria and download the report. I'm trying to use requests to do it automatically.

So far I have:

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)

I can login the site with the first post, and download the page content of report page.

However, every time I do requests.post on the report page and pass in the params to fill the form, it redirect me to a page with error messages:

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.

Is there anyway to go around it ?

Thanks !

Upvotes: 2

Views: 3234

Answers (1)

John Mee
John Mee

Reputation: 52253

Sounds like they're actually inspecting the HTTP_REFERER and denying posts from foreign places. Try adding a http_referer header to the request, something like:

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

You'll need to work out what value they're expecting to see in my_referer. Probably just their own domain name.

Upvotes: 2

Related Questions