简体   繁体   English

我无法传递 Content-Type header 并且内容在 POST python 请求中始终为 0

[英]I can't pass the Content-Type header and the content is always 0 on POST python request

I'm trying to make a post request with python, but it's not working我正在尝试使用 python 发出发帖请求,但它不起作用

import requests

payload = { 'accountID':'20176429'}

h = {'Content-Type': 'application/x-www-form-urlencoded'}

r = requests.post("https://www.simplicialsoftware.com/api/account/GetPlayerProfile", data=payload, headers=h)

print(r.status_code, r.reason)
print(r.headers)
print(r.text[:300] + '...')

Output: Output:

404 Not Found
{'Server': 'nginx/1.20.0', 'Date': 'Sun, 03 Oct 2021 14:00:44 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'Expires': '-1', 'Strict-Transport-Security': 'max-age=2592000'}
...

When I make the same request with Insomnia:当我对 Insomnia 提出同样的要求时:

在此处输入图像描述

在此处输入图像描述

If I remove the Content-Type header from Insomnia I get the 404 error:如果我从 Insomnia 中删除 Content-Type header,我会收到 404 错误:

在此处输入图像描述

I'm running the program from the terminal, using python3 version 3.6.9 with the command:我正在从终端运行程序,使用 python3 版本 3.6.9 和命令:

python3 request.py

When I use the endpoint: https://www.simplicialsoftware.com/ , I get:当我使用端点时: https://www.simplicialsoftware.com/ ,我得到:

200 OK
{'Server': 'nginx/1.20.0', 'Date': 'Sun, 03 Oct 2021 14:44:25 GMT', 'Content-Type': 'text/html', 'Content-Length': '15359', 'Connection': 'keep-alive', 'Last-Modified': 'Thu, 30 Sep 2021 04:23:26 GMT'}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Nebulous</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="keywords" content="nebulous, simplicial, orborous, rebellious, simplicial software">
<meta name="author" content="Andre Luiz Lourenco"/>

What is wrong?怎么了? some help?一些帮助?

I run you code and got a valid response:我运行你的代码并得到有效响应:

200 OK
{'Server': 'nginx/1.20.0', 'Date': 'Sun, 03 Oct 2021 14:20:56 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive'}
{"profile":"É Fda isso \uD83C\uDF42\n\n\n  ت ؛Thnnmate 座","customSkinID":0,"setNamePrice":1000,"banned":false,"chatBanned":false,"arenaBanned":false,"relationship":"NONE","profileColors":[255],"profileFonts":[],"profileFont":0,"hasCommunitySkins":false,"hasCommunityPets":false,"hasCommunityParticles...

Check any.network settings that you might have configured in your pc that block or redirect the message检查您可能在您的电脑中配置的阻止或重定向消息的任何网络设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 基于Content-Type标头的Python / Django REST Framework POST - Python/Django REST Framework POST based on Content-Type header 如何使用django.test.Client发出没有Content-Type标头的HTTP请求? - How can I make an HTTP request with no Content-Type header using django.test.Client? Ajax,内容类型标头和python - Ajax, content-type header and python Python HTTP标头内容类型边界 - Python HTTP Header Content-Type boundary 当Python可以时,为什么不能仅将Content-Type:text / html添加到文本文件中? - Why can't I just add Content-Type:text/html to a text file when Python can? 无论 Content-Type 标头如何,都可以在 Python Flask 中获取原始 POST 正文 - Get raw POST body in Python Flask regardless of Content-Type header Python 请求不发送 {&quot;Content-Type&quot;:&quot;application/json&quot;} 标头或只是忽略 HTTP POST 中的正文 - Python requests not sending {"Content-Type":"application/json"} header or is just ignoring body in HTTP POST urllib.Request 删除 Content-Type 标头 - urllib.Request remove Content-Type header Content-Type 请求 header 错误处理未正确返回 - Content-Type request header error handling not returning correctly 如何在 FastAPI 请求 header 中限制内容类型 - How to restrict content-type in FastAPI request header
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM