当使用 gunicorn 新贵运行我的应用程序时,我得到:
TypeError: 'newline' is an invalid keyword argument for this function
但是,当我从命令行运行它时,我没有问题。
我见过的解决方案表明newline
应该在文件打开中,而不是csv.writer
. 正如你所看到的,我确实在文件打开中找到了它。
要重新创建:
my_app.py
到/home/--你的家--/chmod u+x /home/--your home--/my_app.py
my_upstart.conf
到 /etc/init/my_upstart.conf
以替换您的主目录sudo service my_upstart start
curl localhost:5001/vis
-H "内容类型:文本/csv"sudo cat /var/log/upstart/my_upstart.log
在my_upstart.log
,你会看到TypeError
上面提到的
my_app.py
#!/usr/bin/python3
from flask import Flask, request
app = Flask(__name__)
@app.route('/vis/', strict_slashes=False)
def vis():
with (open('~/test.csv', mode='w', newline='')) as f:
writer = csv.writer(f)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)
my_upstart.conf
description "Gunicorn config file for serving the Wellness app"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid ubuntu
setgid ubuntu
script
cd /home/<your home>/
exec gunicorn --bind 0.0.0.0:5001 my_app:app
end script
gunicorn 使用的是 python 2,它是相应的分发包,而我使用的是 python 3。按照以下步骤修复:
sudo pip3 install gunicorn
/usr/bin/gunicorn
,
#!/usr/bin/python3
(而不是python
)和gunicorn --version
所说的相符的地方更改了 gunicorn 版本。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句