Answer the question
In order to leave comments, you need to log in
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
. 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
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]>
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 questionAsk a Question
731 491 924 answers to any question