Python Forum
Generate a report in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Generate a report in Python (/thread-20623.html)



Generate a report in Python - qureshi - Aug-22-2019

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)



RE: Generate a report in Python - Larz60+ - Aug-22-2019

400 is a site not found error.
That's 400 - Bad request.
recheck your URL


RE: Generate a report in Python - ndc85430 - Aug-24-2019

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.