0

I have a curl POST request that returns a CSV in the terminal as expected. The following format is provided in the RJMetrcis documentation (see "Export figure data"). Here is the curl request in bash:

curl --data-raw "format=csv&includeColumnHeaders=1" -H "X-RJM-API-Key: myapikey" https://api.rjmetrics.com/0.1/figure/12345/export

Alternatively, using -d instead of --data-raw also works

However, when replicating this with the help of a previous post using requests in Python, an error is returned:

url = "https://api.rjmetrics.com/0.1/figure/12345/export"

payload = "'{\"format\":\"csv&includeColumnHeaders=1\"}'"
headers = {
  'X-RJM-API-Key': 'myapikey'
}

response = requests.request("POST", url, headers=headers, params=payload)
response.text

'{"Error":"Invalid Argument: CSV is currently the only supported format for SQL Reports"}'

This is a specific error returned by the API indicating a CSV format is not requested (when -d is left out of the bash command, the same error is raised). However, both requests are syntactically the same. What could be the Python issue here? Is there a preferred method to pass parameters?

1 Answer 1

2
import requests

data = {
    'format': 'csv',
    'includeColumnHeaders': 1
}

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
    'X-RJM-API-Key': 'yourapi'
}


def main(url):
    r = requests.post(url, data=data, headers=headers)
    print(r)


main("https://api.rjmetrics.com/0.1/figure/12345/export")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.