我正在使用 Python编写 Notion 入门指南,每次发送 post 请求时都会出现此错误:
{'object': 'error', 'status': 400, 'code': 'invalid_json', 'message': 'Error parsing JSON body.'}
这是我用我的代码尝试过的:
# Notion Application
import json, requests
file = open('SECRETS.json') # Opens the file
data = json.load(file) # loads the data then stores in variable called data
# Secret here:
secret = data['id']
# Database information here:
database = data['database_tasks']
file.close() # close file
url = 'https://api.notion.com/v1/pages'
# Headers
headers = {
'Authorization': f'Bearer {secret}',
'Content-Type': 'application/json',
'Notion-Version': '2021-05-13'
}
# Data input
data_input = {
"parent": { "database_id": f"{database}" },
"properties": {
"Name": {
"title": [
{
"text": {
"content": "Yurts in Big Sur, California"
}
}
]
}
}
}
# check request
response = requests.post(url, headers=headers, data=data_input)
print(response.json())
我已经搜索了错误,但我看不到我做错了什么。我遵循了他们在网站上以 python 形式提供的 cURL 示例。