0

The SyntaxError: invalid syntax error points me to line 75, but I cant see what is wrong there. Please I need help to identify possible reason. When i run Flask, the server crashes.

    192.168.1.172 - - [13/Mar/2021 22:01:32] "GET /favicon.ico HTTP/1.0" 500 -
    Error on request:
    Traceback (most recent call last):
    File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 323, in run_wsgi
    execute(self.server.app)
    File "/usr/local/lib/python3.9/site-packages/werkzeug/serving.py", line 312, in execute
    application_iter = app(environ, start_response)
    File "/usr/local/lib/python3.9/site-packages/flask/cli.py", line 343, in __call__
    rv = self._load_unlocked()
    File "/usr/local/lib/python3.9/site-packages/flask/cli.py", line 330, in _load_unlocked
    self._app = rv = self.loader()
    File "/usr/local/lib/python3.9/site-packages/flask/cli.py", line 388, in load_app
    app = locate_app(self, import_name, name)
    File "/usr/local/lib/python3.9/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
    File "/home/ubuntu/finance/application.py", line 75
    def buy():
    ^
    SyntaxError: invalid syntax
    @app.route("/buy", methods=["GET", "POST"])
    @login_required
    def buy():
        """Buy shares of stock"""
        if request.method == "POST":
3
  • Keep backing up lines in the program. There's likely a mismatched (not closed) something, eg parens (()) or quotes (") in a previous line. Mar 14 at 3:28
  • Thanks so so much @DinoCoderSaurus. The closing bracket for my return function was missing, just the line before the next decorator. It works now. Please may I just ask so I could learn. What in the error message pointed to this suggestion please? How can I tell this form the error message displayed. I will appreciate please.
    – Idongesit
    Mar 14 at 7:06
  • Experience. 40 years of writing bugs :). Since it showed "syntax error" on the first character of a "good" line of code (it came from the distro), I knew to search backwards. Mar 14 at 18:03

You must log in to answer this question.

Browse other questions tagged .