bash脚本中的Mutt在python(flask)应用程序中引发错误

时间:2016-10-28 20:51:11

标签: python bash flask mutt

我认为这里的主要问题是使用mutt命令: mutt -s "Title" -a $file -- "$address" < $DIR/message.txt。 如果我从脚本中删除它,就没有错误,所以也许有人会知道发生了什么。

这是一个使用flask的python应用程序。这是一个有问题的方法:

@app.route('/send', methods=['POST'])
def send():
start_date = '2016-10-20'
end_date = '2016-10-28'
path = os.path.dirname(os.path.realpath(__file__))
script = path + '/script.sh'
address = 'my@mail.com'
subprocess.check_call([script, start_date, end_date, address])
return json.dumps({
    'message': 'Your message is sent!'
})

子流程运行脚本:

#!/bin/bash
start_date="$1"
end_date="$2"
address="$3"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$file="My_super_file"
out=$(R -e "rmarkdown::render('$DIR/generate_file.Rmd', output_file = $file)")
mutt -s "Title" -a $file -- "$address" < $DIR/message.txt

生成文件时,我收到这样的错误:

[2016-10-28 16:03:06,857] ERROR in app: Exception on /send [POST]
Traceback (most recent call last):
  File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/admin/anaconda2/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "Users/admin/mydemoapp/app/appdemo/views.py", line 18, in send
    subprocess.check_call([script, start_date, end_date, address])
  File "/Users/admin/anaconda2/lib/python2.7/subprocess.py", line 541, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['/Users/admin/mydemoapp/app/appdemo/script.sh', '2016-10-20', '2016-10-28', u'my@mail.com']' returned non-zero exit status 1

0 个答案:

没有答案