0

I need to extract data from a source system using requests library in python. The way in which the api has been configured, I need to make a post request with some json data to get back results. Since its a public API no authorization is required.

I faced no issue while extracting data using POSTMAN but when I try to do the same using requests library I get 406 status code as response.

In POSTMAN I pass JSON details in the body of the request, here I tried passing the same details along with the post request using json and data parameter but both gave the same status code. Also, I tried adding headers from postman to fix the issue but that didn't work as well

import requests 
header = {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, defalte, br",
    "Content-Type": "text/plain"
}
response = requests.post('api_url', headers= header, json={
    "facilityName": "",
    "filters": {
        "locationType": [""]
    },
    "geoDistanceOptions": {
        "location": "Indianapolis, IN",
        "radius": 5500
    },
    "locationType": "",
    "page": 1,
    "pageSize": 6000,
    "stateCode": ""
}
)

print("Status Code: ", response.status_code)

Note: api_url is not a variable, I just added it as a place holder for the api

  • Maybe this post will help: https://stackoverflow.com/questions/9733638/how-to-post-json-data-with-python-requests?rq=1 – SimonT Jul 17 '21 at 15:52

0 Answers0