简体   繁体   English

发送请求时出现 Content-Type 错误

[英]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.

相关问题 Content-Type 请求 header 错误处理未正确返回 - Content-Type request header error handling not returning correctly Flask-Restful 错误:请求 Content-Type 不是 'application/json'。"} - Flask-Restful Error: request Content-Type was not 'application/json'."} 为什么在未发送请求时,wsgiref.simple_server将请求的内容类型报告为“文本/纯文本”? - Why does wsgiref.simple_server report content-type of request as 'text/plain' while none was sent? 我无法传递 Content-Type header 并且内容在 POST python 请求中始终为 0 - I can't pass the Content-Type header and the content is always 0 on POST python request Python:如何获取 URL 的内容类型? - Python: How to get the Content-Type of an URL? 强制 Content-Type 或公开 Flask 中已知内容类型的 request.data - Force Content-Type or expose request.data in Flask for known content-type 发送电子邮件(SMTP)时应选择哪种内容类型 - which content-type should be chosen when sending email (SMTP) 在 AWS Lambda 上的 python 中使用枕头 package 保存图像时出现错误/错误的内容类型 - Error/Wrong Content-Type while saving image using pillow package in python on AWS Lambda 如何使用django.test.Client发出没有Content-Type标头的HTTP请求? - How can I make an HTTP request with no Content-Type header using django.test.Client? urllib.Request 删除 Content-Type 标头 - urllib.Request remove Content-Type header
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM