O
O
organica2020-06-26 12:30:30
Python
organica, 2020-06-26 12:30:30

GET request works in POSTman but returns 403 in python requests?

Actually, the problem is the following:
Postman works fine and returns the expected result
5ef5bfc569c0b193705559.png

. And python issues a 403 code for a similar request. Although the titles seem to be the same. What does he, the dog, lack?

import requests
from pprint import pprint

url = 'http://ovga.mos.ru:8080/_ajax/pass/list?search={%22grz%22:%22К239ММ159%22}&sort=validitydate&order=desc'

headers = {"X-Requested-With": "XMLHttpRequest",
           'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                         'Chrome/54.0.2840.99 Safari/537.36',
           }
response = requests.get(url, headers)

pprint(response)

<Response [403]>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Yakushenko, 2020-06-26
@organica

You didn't pass all the titles. Postman by default generates some headers on its own, this is how it connects normally:

headers = {
    'Host': 'ovga.mos.ru',
    'User-Agent': 'Magic User-Agent v999.26 Windows PRO 11',
    'Accept': '*/*',
    'Accept-Encoding': 'gzip, deflate, br',
    'Connection': 'keep-alive',
    'X-Requested-With': 'XMLHttpRequest'
}
url = 'http://ovga.mos.ru:8080/_ajax/pass/list?search={"grz":"К239ММ159"}&sort=validitydate&order=desc'
response = requests.get(url, headers=headers)

<Response [200]>

S
ScriptKiddo, 2020-06-26
@ScriptKiddo

Generate a Python snippet so you don't miss anything
https://learning.postman.com/docs/postman/sending-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question