【发布时间】:2019-08-10 05:50:28
【问题描述】:
我写了一个小烧瓶应用程序。 我将带有 json 数据(python 脚本)的请求发送到烧瓶服务器(ubuntu 18.04 和 python 3.6.7), 和服务器评估这些数据...
客户:
data = { 'serial': '12345'
'printerConfig': {
'virtualPrinter1': 'physicalPrinter1',
'virtualPrinter2': 'physicalPrinter2',
'virtualPrinter3': 'physicalPrinter3'
}
}
r = requests.get("http://127.0.0.1/webservice", json=data)
服务器:
@app.route('/', methods=['GET', 'POST'])
def webservice():
if request.method == 'GET':
serial = request.json['serial'] if 'serial' in request.json else None
printerConfig = request.json['printerConfig'] if 'printerConfig' in request.json else None
我已经在开发服务器的 pyCharm 中测试了这段代码,并且一直运行良好。
之后,我尝试将其实现到 Apache2 服务器。 现在我在 apache-error.log 中收到以下错误消息。
ERROR:flask.app:Exception on / [GET]
Traceback (most recent call last):
...
File "/var/www/html/webservice/webservice.py", line xx, in webservice
serial = request.json['serial'] if 'serial' in request.json else None
TypeError: argument of type 'NoneType' is not iterable
request.json 的打印只显示无。 开发服务器上正在运行完全相同的代码。
我也尝试了 request.data 而不是 request.json,结果相同。
Apache2 有专门的设置吗? 有人有想法吗?
最好的问候 浮动
【问题讨论】:
标签: python json flask apache2.4