Sign in | Sign up

Simple Python Query Request

Tagged:

Currently contains 2 posts

Avatar

September 29, 2019 11:43

bethanybeachbum

Can someone please, please, please reply with a simple Python file that works requesting data from
https://trackapi.nutritionix.com/v2/natural/nutrients ?

Here is mine that does not work:
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `
import requests
import json

url = “https://trackapi.nutritionix.com/v2/natural/nutrients”
headers = {
‘x-app-id’: ‘<app-id>’,
‘x-app-key’: ‘<app-key>’,
‘x-remote-user-id’:‘0’,
‘content-type’: ‘application/json’,
‘accept’: ‘application/json’
}
data={ ‘query’: ‘apple’ }
r = requests.post(url, headers=headers, data=data, json=body)
print(r.status_code)
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `
this is the response:
400
{"message":“child \”query\" fails because [\“query\” is required]“,”id":“fb617b38-c2fe-479c-8a99-d35fd898f6ae”}

Avatar

September 30, 2019 02:27

bethanybeachbum

I removed ‘content-type’ and ‘accept’ in the headers and I am able to get a 200 response.

Reply to thread