Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:23:10+00:00 2026-06-02T13:23:10+00:00

I am trying to make a simple api in Flask, the first step being

  • 0

I am trying to make a simple api in Flask, the first step being getting the POST json data. (I just want to print it for now) This is my code and when I request /api with json data, it returns a 500 error. Any thoughts on why this is happening?

from flask import Flask, request, Response
app = Flask(__name__)

@app.route('/')
def root_response():
    return "Hello World."

@app.route('/api', methods=['POST', 'GET'])
def api_response():
    if request.method == 'POST':
        return request.json

if __name__ == '__main__':
    app.run()

The curl command:

$ curl -H "Content-Type: application/json" --data @body.json http://127.0.0.1:5000/api
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>

body.json:

{
"please": "print",
"me": "now"
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:23:11+00:00Added an answer on June 2, 2026 at 1:23 pm

    First what you want to do is enable debug mode so Flask will actually tell you what the error is. (And you get the added benefit of flask reloading every time you modify your code!)

    if __name__ == '__main__':
        app.debug = True
        app.run()
    

    Then we find out our error:

    TypeError: 'dict' object is not callable
    

    You’re returning request.json, which is a dictionary. You need to convert it into a string first. It’s pretty easy to do:

    def api_response():
        from flask import jsonify
        if request.method == 'POST':
            return jsonify(**request.json)
    

    There you are! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make simple script using jquery $post function to pass data to
I'm trying to make a simple HTTP post a endpoint with ONLY url arguments.
Trying to make a call and retrieve a very simple, one line, JSON file.
I am trying to make a simple Facebook app that takes some data from
i am just trying to make a simple ajax call to shorten a url
I am trying to add just a simple Twitter icon that will make the
I'm trying to make a simple site that uses php and the Twitter API
I am trying to make a query with Hibernate criteria API. It looks simple
I'm trying to make a php api request to simply make a simple paste
I am trying to make a simple rest api with rails using the respond_with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.