Python Forum
POST `api` 415 (Unsupported Media Type)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
POST `api` 415 (Unsupported Media Type)
#1
A little off the scope of Python but I'm trying to get things done in the frontend before integrating the Django backend.
I have tried different header objects to this simple html page from where I'm to send Post request to an API endpoint. It's a form data of username and the password. I keep getting
Error:
POST https://some/api/endpoint/ 415 (Unsupported Media Type)
error message.


<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" type="text/css" href="styly.css">
    <title>Login</title>
  </head>

<body>
    <form>
          <input type="text" id="username" name="user_name" placeholder="Username"> <br>  <br>
          <input type="password" id="password" name="password" placeholder="Password"> <br>  <br>

          <input type="submit" value="Submit">
      </form>

<script>
      const url = "https://some/apo/endpoint/";
      const formEl = document.querySelector("form");
      formEl.addEventListener("submit", async (e) => {
        e.preventDefault();
        const formData = new FormData(formEl);
        const formDataSerialized = Object.fromEntries(formData);
        const jsonObject = {
          ...formDataSerialized,
          sendToSelf: formDataSerialized.sendToSelf ? true : false,
        };
        try {
          const response = await fetch(url, {
            method: "POST",
            body: JSON.stringify(jsonObject),
            headers: {
              "Content-Type": "application/json",

            },
            mode: "no-cors"
          });
          const json = await response.json();
          console.log(json);
        } catch (e) {
          console.error(e);
          alert("there as an error");
        }
      });
    </script>


  </body>
  </html>
Reply
#2
Have you tried specifying a different Content-Type? I'm not sure what content type would be correct, but it's possible that is causing the HTTP 415 response. Also, check and make sure everything is correct in the jsonObject.
Dexty likes this post
Reply
#3
on the thought of his buddy zhuge qing, zhang chulan and feng baobao came to resolve the case with the help of "anywhere" business enterprise. how does zhang chulan display his competencies to assist the king trap the black hand backstage? what wonderful overall performance will zhuge qing, wang ye and others have? who're the people who covet the "8 wonders"? "under one guy-becoming a member of the world" may be introducedsoon!

voip phone system service provider
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Django and AWS S3 media storage rwahdan 0 1,431 Mar-06-2022, 08:47 AM
Last Post: rwahdan
  sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type. Prince_Bhatia 3 14,998 Apr-03-2018, 03:40 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020