Home > Software engineering >  I can't pass the Content-Type header and the content is always 0 on POST python request
I can't pass the Content-Type header and the content is always 0 on POST python request

Time:10-04

I'm trying to make a post request with python, but it's not working

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'}
...

When I make the same request with Insomnia:

enter image description here

enter image description here

If I remove the Content-Type header from Insomnia I get the 404 error:

enter image description here

I'm running the program from the terminal, using python3 version 3.6.9 with the command:

python3 request.py

When I use the endpoint: https://www.simplicialsoftware.com/ , I get:

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?

CodePudding user response:

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

  • Related