Python Forum

Full Version: Generate a report in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I an trying to generate using an APi in python. I am using the following code but getting this error:

{"code":400,"message":"Invalid input parameters","status":"error"}

Here is my code:
import requests
import json
api_url = "https://anlyticstts.com//api/insights/v1/reports"

headers = {
    'Content-Type': 'application/json',
    'X-access-key': 'e13168e9f1504d63455'

            }
data = {
    "search_term_ids": [60, 61],
    "product_list_ids": [120],
    "start_date": "20180801",
    "end_date": "20180805",
    "columns": {
        "product": ["crawl_date", "product_name"],
        "status": ["no_longer_available"],
        "ranking": ["search_rank"],
        "pricing": ["price"]
                },
    "page_one_only": True,
    "format": "csv"
        }
r = requests.post(url=api_url, data=data, headers=headers)
print(r.text)
400 is a site not found error.
That's 400 - Bad request.
recheck your URL
No, 404 is resource not found.

400 is a generic bad request status code, so doesn't necessarily indicate that the URL is bad. The request body could be malformed, for instance. I'd check the documentation of the API you're using to check that you're specifying the request in the right way.