0

Below is the piece of code that i have for my api and i have a class auths which has method createuser returning simple int value as of now but when i hit with restapi is gives error. Any idea ?

api.py

from auths import auths
from flask import Flask, url_for
app = Flask(__name__)

@app.route('/')
def api_root():
    #m = auths.createuser()
    return "m"
if __name__ == '__main__':
    app.run()

auths/auths.py

#!/usr/bin/python
class auths:
    def createuser():
        return 1

Error:-

<!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>
pkm
  • 2,683
  • 2
  • 29
  • 44
  • 1
    To debug more easily you can turn on debug mode via `app.run(debug=True)` or by setting debug to true in the config. That way you will not (only) see a 500 html error but the python error that lead flask to emit a 500er. Only use debug mode in development. – syntonym Sep 04 '16 at 06:59

1 Answers1

1

You have to give the argument self for the class functions,

#!/usr/bin/python
class auths:
    def createuser(self):
        return 1

Another problem with the function call,

m = auths()
result = m.createuser()

You have to call like this, result will have value 1 as the class function returns.

Rahul K P
  • 15,740
  • 4
  • 35
  • 52