【发布时间】:2017-11-04 03:09:58
【问题描述】:
当我使用 gunicorn upstart 运行我的应用程序时,我得到:
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 "Content-Type: text/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
【问题讨论】:
标签: python-3.x flask gunicorn