【发布时间】:2020-01-09 10:05:23
【问题描述】:
所以我将我的烧瓶应用程序部署到我的 linux debian VM 并通过 wsgi 和 apache2 (lynx serverIpAdress/mailService) 提供服务。
我的问题:
当我使用命令python mailService.py 运行应用程序时,它运行良好,但是当我尝试通过 apache2 访问它时,出现以下错误:
[wsgi:error] [pid 8771:tid 139918835648256] [client 192.168.1.50:37344] File "/var/www/Bulma/MailService/mailService.wsgi", line 5, in <module>
[wsgi:error] [pid 8771:tid 139918835648256] [client 192.168.1.50:37344] from mailService import app as application
[[wsgi:error] [client 192.168.1.50:37344] File "/var/www/Bulma/MailService/mailService.py", line 2, in <module>
[Thu Jan 09 08:45:42.595785 2020] [wsgi:error] [pid 8771:tid 139918835648256] [client 192.168.1.50:37344] from flask import request, jsonify,json
[Thu Jan 09 08:45:42.595839 2020] [wsgi:error] [pid 8771:tid 139918835648256] [client 192.168.1.50:37344] ImportError: cannot import name 'request' from 'flask' (unknown location)
[Thu Jan 09 08:53:41.179747 2020] [wsgi:error] [pid 8771:tid 139918877611776] [client 192.168.1.50:37366] mod_wsgi (pid=8771): Failed to exec Python script file '/var/www/Bulma/Mai$
我的 mailService.py:
import flask
from flask import request,json
import smtplib
app = flask.Flask(__name__)
app.config["DEBUG"] = True
@app.route('/api/v1/resources/mailFactory',methods=['POST'])
def mailFactory():
Json = request.get_json()
Application = Json['Application']
context = int(Application)
switcher = {
0: themisMailService
}
if Application:
func = switcher.get(context)
return func(Json)
def themisMailService(Json):
sender_email = "test@gmail.com"
receiver_email = "test@gmail.com"
message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
# Login Credentials for sending the mail
server.login(sender_email, "gjwvttjphdrhivoo") #app password inserted
server.sendmail(sender_email, receiver_email, message)
server.quit()
print ("Successfully sent email")
#app.run(host= '0.0.0.0')
附加信息:
- 我在我的工作目录中设置了一个flask-env,但不确定是否有必要。
- 我已经尝试启动命令 pip install flask, pip install request。
- PIP 版本是来自 /usr/lib/python2.7/dist-packages/pip (python 2.7) 的 pip 18.1
- Flask 版本为 Flask 1.1.1
- App.run() 已被我的应用程序评论,因为据我了解,由于 wsgi 已经在为该应用程序提供服务,因此不再需要它。
感谢您的帮助!
【问题讨论】: