M
M
Mayo02018-02-10 20:16:39
Python
Mayo0, 2018-02-10 20:16:39

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:
5a7f256eb9a40671250370.png
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

After execution it gives an error:
Response[405]

I'm not well versed in this area, so there's nothing to even assume.
Traffic police website - stat.gibdd.ru (In it: Uploading road traffic indicators -> Accident cards)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-02-10
@Mayo0

In the original Request Method POST request , and you make requests. get .

M
Mayo0, 2018-02-11
@Mayo0

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 question

Ask a Question

731 491 924 answers to any question