[英]I get a Content-Type error while sending a request
I want to follow another channel with my own channel with the Twitch API.我想用 Twitch API 用我自己的频道关注另一个频道。 I prepared the code in python according to the codes from the Develepor page.
我根据Develepor页面上的代码准备了python中的代码。 But when I make a request I get an error like "Request body was not parsable. Attempted Content-Type: " application / json \ " . My code is below. How can I do it? Can you help me?
但是当我发出请求时,我收到一个错误,例如“请求正文不可解析。尝试的内容类型:”应用程序 / json \“ 。我的代码如下。我该怎么做?你能帮帮我吗?
import requests
headers = {
'Content-Type':'application/json',
'Client-Id': 'clientid',
'Authorization': 'Bearer token',
}
data = {
"to_id": "610766140", "from_id": "664978624"
}
response = requests.post("https://api.twitch.tv/helix/users/follows", headers=headers, data=data)
print(response.text)
You told it you were going to send JSON, then you didn't send JSON.你告诉它你要发送 JSON,然后你没有发送 JSON。
import requests
headers = {
'Content-Type':'application/json',
'Client-Id': 'clientid',
'Authorization': 'Bearer token',
}
data = {
"to_id": "610766140", "from_id": "664978624"
}
response = requests.post("https://api.twitch.tv/helix/users/follows", headers=headers, json=data)
print(response.text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.