0

I an trying to Post CSV using python request. 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)
3
  • Shouldn't your api url be api_url = "anlyticstts.com/api/insights/v1/reports" instead of api_url = "anlyticstts.com//api/insights/v1/reports" Commented Aug 22, 2019 at 10:32
  • still getting the same error? Commented Aug 22, 2019 at 11:29
  • I think you should try requests.post(api_url, data=data, headers=headers) instead of requests.post(url=api_url, data=data, headers=headers) Commented Aug 22, 2019 at 11:44

1 Answer 1

1

You can try this sample code import json

r = requests.post(api_url, data=json.dumps(data), headers=headers)

instead of

r = requests.post(url=api_url, data=data, headers=headers)

Sign up to request clarification or add additional context in comments.

1 Comment

Please try with json.dumps your data. If it does not work then can you check your data while sending is proper json data

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.