Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: how to solve "TypeError: 'str' object is not callable"

So I have this flask api script

@app.route('/request', methods=["POST"])
def reqpost():
     content = request.get_json()
     h = content['type']
     if h == 'one'():
          typeone()
          return ("running type one")
     elif h == 'two'():
          typetwo()
          return ("running type two")
     else:
          return ("error!")

and this is the json data that would be sent in a request

{
  "type": "typeone"
}

but when I send a request to the server I get this on the server output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TypeError: ‘str’ object is not callable

for these lines

if h == 'one'():
  # stuff
# and
elif h == 'two'():
  # stuff

I have tried adding str() in those lines but I still get that dumb error

any help would be nice thanks 🙂

>Solution :

ty removing ():

@app.route('/request', methods=["POST"])
def reqpost():
     content = request.get_json()
     h = content['type']
     if h == 'one':
          typeone()
          return ("running type one")
     elif h == 'two':
          typetwo()
          return ("running type two")
     else:
          return ("error!")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading