[英]Python/Django REST Framework POST based on Content-Type header
[英]I can't pass the Content-Type header and the content is always 0 on POST python request
我正在嘗試使用 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:
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'}
...
當我對 Insomnia 提出同樣的要求時:
如果我從 Insomnia 中刪除 Content-Type header,我會收到 404 錯誤:
我正在從終端運行程序,使用 python3 版本 3.6.9 和命令:
python3 request.py
當我使用端點時: 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"/>
怎么了? 一些幫助?
我運行你的代碼並得到有效響應:
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...
檢查您可能在您的電腦中配置的阻止或重定向消息的任何網絡設置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.