我有以下代码:
t1 = threading.Thread(target = app.run, args = (host='0.0.0.0', port = 443))
它给了我一个错误:
File "/home/deploy/tgbot/tgbot.py", line 1170
t1 = threading.Thread(target = app.run, args = (host='0.0.0.0', port = 443))
^
有什么问题?
答案 0 :(得分:1)
app.run
的顺序参数可以在元组中传递(用括号构造,但没有名称)。必须在字典中传递命名参数。字典由dict()
或花括号构成,而不是括号。
由于host
和port
是app.run
的前两个参数,因此以下任何一个都应该有效:
# 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}))