Answer the question
In order to leave comments, you need to log in
How to fix the error "405 Method Not Allowed" when downloading the accident database from the traffic police website?
Good day.
On the traffic police website, you need to download the accident database for several years, but the site allows you to download data at a time only for 14 days. In this regard, it was decided to write a script and download files.
In developer mode in the chrome browser, the request looks like this:
I got the following implementation:
import requests
payload = {"date_s":"01.11.2017","date_end":"14.11.2017","ParReg":"877","order":{"type":1,"fieldName":"dat"},"reg":["45"],"ind":"44","exportType":1}
r = requests.get("http://stat.gibdd.ru/getCardsListCSV", data = payload)
r
Response[405]
Answer the question
In order to leave comments, you need to log in
In the original Request Method POST request , and you make requests. get .
Thanks everyone, here is the working code
import requests
import json
from fake_useragent import UserAgent
fakeBrowser = UserAgent()
urlPost = "http://stat.gibdd.ru/getCardsListCSV"
headers = {'Accept': '*/*','Accept-Encoding': 'gzip, deflate','Accept-Language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7','Connection': 'keep-alive','Content-Length': '209','Cookie': '_ga=GA1.2.1355086731.1518262575; _gid=GA1.2.370010749.1518262575; JSESSIONID=5EF4597155A357022299703AF87D0DF5','Host': 'stat.gibdd.ru','Referer': 'http://stat.gibdd.ru/','X-Requested-With': 'XMLHttpRequest','Origin': 'http://stat.gibdd.ru','content-type': 'application/json;charset=utf-8','User-Agent': fakeBrowser.opera}
payload = {"data":"{\"date_s\":\"07.11.2017\",\"date_end\":\"09.11.2017\",\"ParReg\":\"877\",\"order\":{\"type\":1,\"fieldName\":\"dat\"},\"reg\":[\"45\"],\"ind\":\"44\",\"exportType\":1}"}
r = requests.post(urlPost, json=payload, headers=headers)
r.status_code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question