{“错误”:[ {“详细信息”:“错误请求,JSON负载应位于名为”sheet 1“的根属性中

qyyhg6bp  于 2023-02-06  发布在  其他
关注(0)|答案(1)|浏览(79)

我之前发布了一个关于这段代码的问题,得到了一个解决了一个问题的答案,但是现在我得到了一个新的错误,我不理解这个错误或bug。我还在用Mac在PyCharm上编码🖥,如果这能改变什么的话。这段代码来自于Angela Yu博士的第333讲,100天的代码。感谢@Tim Roberts对我上一个问题的帮助!

#------------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
4uqofj5v

4uqofj5v1#

应该使用“sheet1”代替“workout”

相关问题