简体   繁体   中英

Syntax error flask application

I have following code:

t1 = threading.Thread(target = app.run, args = (host='0.0.0.0', port = 443))

and it gives me an error:

File "/home/deploy/tgbot/tgbot.py", line 1170
t1 = threading.Thread(target = app.run, args = (host='0.0.0.0', port = 443))
                                                    ^

What is the problem?

The sequential arguments for app.run can be passed in a tuple (constructed with parentheses, but no names). The named arguments must be passed in a dictionary. Dictionaries are constructed with dict() or curly braces, not parentheses.

Since host and port are the first two arguments to app.run , any of the following should work:

# positional args, passed as a tuple
t1 = threading.Thread(target=app.run, args=('0.0.0.0', 443))

# named args, passed in a dictionary created via dict()
t1 = threading.Thread(target=app.run, kwargs=dict(host='0.0.0.0', port=443))

# named args, passed in a dictionary created via {}
t1 = threading.Thread(target=app.run, kwargs={'host': '0.0.0.0', 'port': 443}))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM