Pixela无法创建图表(HTTP错误:400)- 用户不存在或令牌错误
我在尝试创建一个图表时,遇到了一个错误信息(HTTP错误)400。可以从下面的信息看到,用户已经成功创建:
import requests
USERNAME = "testusermichael"
TOKEN = "2ködfajfölN!!"
GRAPH_ID = "graph1"
pixela_endpoint = "https://pixe.la/v1/users"
user_params = {
"token": TOKEN,
"username": USERNAME,
"agreeTermsOfService": "yes",
"notMinor": "yes",
}
graph_endpoint = f"{pixela_endpoint}/{USERNAME}/graphs"
graph_config = {
"id": GRAPH_ID,
"name": "Walking Graph",
"unit": "Km",
"type": "float",
"color": "shibafu"
}
headers = {
"X-USER-TOKEN": TOKEN
}
response = requests.post(url=graph_endpoint, json=graph_config, headers=headers)
print(response.text)
再次尝试创建用户时的响应:
{
"message": "This user already exist.",
"isSuccess": false
}
尝试创建图形时的响应:
{
"message": "User testusermichael does not exist or the token is wrong.",
"isSuccess": false
}
1 个回答
0
根据评论讨论,看来这个API对某些字符不太友好,可能是因为字符编码的问题,或者它根本就不接受非字母数字的令牌。
解决方法很简单,就是使用一个简单的字母数字组合的令牌。这个令牌的长度可以达到128个字符。
你可以使用像这个网站来生成一个长的令牌,然后用它来验证其他请求。