I posted a question about this code earlier and got an answer that got rid of one problem but now I'm getting a new error, and I dont uderstand the error or bug. Also im coding on PyCharm using a Mac🖥, if that changes anything. The code is from lecture 333, of 100 days of code by Dr. Angela Yu. Thanks to @Tim Roberts for the help on my last problem!
#------------New_code------------#
import requests
from datetime import datetime
GENDER = "male"
WEIGHT_KG = 58.740212
HEIGHT_CM = 177.8
AGE = 13
APP_ID = "be2*****"
API_KEY = "4fa82da*************************"
exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise"
sheet_endpoint = "https://api.sheety.co/0a5644021c9c3815973ccd3f25595467/myWorkouts/sheet1"
exercise_text = input("Tell me which exercises you did: ")
headers = {
"x-app-id": APP_ID,
"x-app-key": API_KEY,
}
parameters = {
"query": exercise_text,
"gender": GENDER,
"weight_kg": WEIGHT_KG,
"height_cm": HEIGHT_CM,
"age": AGE
}
response = requests.post(exercise_endpoint, json=parameters, headers=headers)
result = response.json()
today_date = datetime.now().strftime("%d/%m/%Y")
now_time = datetime.now().strftime("%X")
bearer_headers = {
"Authorization": f"Bearer {'TOKEN'}"
}
for exercise in result["exercises"]:
sheet_inputs = {
"workout": {
"date": today_date,
"time": now_time,
"exercise": exercise["name"].title(),
"duration": exercise["duration_min"],
"calories": exercise["nf_calories"]
}
}
sheet_response = requests.post(sheet_endpoint, json=sheet_inputs, headers=bearer_headers)
print(sheet_response.text)
#------------New_output------------#
Tell me which exercises you did: (I entered: run 3 miles)
{
"errors": [
{
"detail": "Bad Request. The JSON payload should be inside a root property called 'sheet1'. Check https://sheety.co/docs for more details."
}
]
}
Process finished with exit code 0
instead "workout" you should use "sheet1"