'How to get the data from POST request (API) in Python from sothebys site

I hope you are doing well. I have post request from which I want to get data in my jupyter notebook. I used the POSTMAN to check the data. Its working fine in the Postman and getting the data. But I want to get it from jupyter notebook with Python its showing error. Can you please help me. Please check the below POSTMAN url and param and body.

Post Url = https://o28sy4q7wu-2.algolianet.com/1/indexes/*/queries?x-algolia-agent=Algolia%20for%20JavaScript%20(3.33.0)%3B%20Browser%20(lite)%3B%20react%20(16.3.2)%3B%20react-instantsearch%20(5.7.0)%3B%20JS%20Helper%20(2.28.1)&x-algolia-application-id=O28SY4Q7WU&x-algolia-api-key=e732e65c70ebf8b51d4e2f922b536496


Key: x-algolia-agent                                                                           
Value : Algolia%20for%20JavaScript%20(3.33.0)%3B%20Browser%20(lite)%3B%20react%20(16.3.2)%3B%20react-instantsearch%20(5.7.0)%3B%20JS%20Helper%20(2.28.1)

Key : x-algolia-application-id
Value : O28SY4Q7WU

Key : x-algolia-api-key
Value : e732e65c70ebf8b51d4e2f922b536496

Body : {"requests":[{"indexName":"query_suggestions_bsp_dotcom_en","params":"query=&hitsPerPage=7&page=120&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&facets=%5B%5D&tagFilters="}]}

by using these parameters its working fine in Post man. Please check the Python code for Post request below.

import requests

url = 'https://o28sy4q7wu-2.algolianet.com/1/indexes/*/queries?x-algolia-agent=Algolia%20for%20JavaScript%20(3.33.0)%3B%20Browser%20(lite)%3B%20react%20(16.3.2)%3B%20react-instantsearch%20(5.7.0)%3B%20JS%20Helper%20(2.28.1)&x-algolia-application-id=O28SY4Q7WU&x-algolia-api-key=e732e65c70ebf8b51d4e2f922b536496'
payload = {'requests': '"indexName":"query_suggestions_bsp_dotcom_en","params":"query=&hitsPerPage=7&page=0&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&facets=%5B%5D&tagFilters="'}

x = requests.post(url, data = payload)

print(x.text)

Please help me to get the data in Jupyter notebook with python.

Thank you !



Solution 1:[1]

Hi you must change the payload.
Put this one:

payload = '{"requests":[{"indexName":"query_suggestions_bsp_dotcom_en","params":"query=&hitsPerPage=7&page=0&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&facets=%5B%5D&tagFilters="}]}'   

Works fine for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MeT