hualos
hualos copied to clipboard
TypeError error and blank web while running with keras 1.2.1
When I run python api.py, and start keras program with remote callbacks, I got these message:
::ffff:127.0.0.1 - - [2017-02-14 11:51:15] "POST //publish/epoch/end/ HTTP/1.1" 500 161 0.000479 Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 936, in handle_one_response self.run_application() File "/usr/local/lib/python2.7/dist-packages/gevent/pywsgi.py", line 909, in run_application self.result = self.application(self.environ, self.start_response) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1994, in call return self.wsgi_app(environ, start_response) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1615, in full_dispatch_request return self.finalize_request(rv) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1630, in finalize_request response = self.make_response(rv) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1740, in make_response rv = self.response_class.force_type(rv, request.environ) File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 847, in force_type response = BaseResponse(*_run_wsgi_app(response, environ)) File "/usr/local/lib/python2.7/dist-packages/werkzeug/test.py", line 871, in run_wsgi_app app_rv = app(environ, start_response) TypeError: 'dict' object is not callable Tue Feb 14 11:51:15 2017 {'REMOTE_PORT': '39644', 'HTTP_HOST': 'localhost:9000', 'REMOTE_ADDR': '::ffff:127.0.0.1', (hidden keys: 23)} failed with TypeError
I checked my gevent and flask version:
- gevent1.0.2
- flask0.10.1
So I modifed api.py like these:
@app.route("/publish/epoch/end/", methods=['POST'])
def publish():
#payload = request.form.get('data')
payload = unquote(request.data.split('=')[1]).replace('+','')
try:
data = json.loads(payload)
except:
return {'error':'invalid payload'}
def notify():
msg = str(time.time())
for sub in subscriptions[:]:
sub.put(payload)
gevent.spawn(notify)
return "OK"
Then everything goes OK
This is awesome thanks for sharing. This helped me get it to work. I believe there are two things we need to add here to make it work.
from urllib import unquote
and
@app.route("/publish/epoch/end/", methods=['POST'])
def publish():
#payload = request.form.get('data')
payload = unquote(request.data.split('=')[1]).replace('+','')
try:
data = json.loads(payload)
except:
return {'error':'invalid payload'}
def notify():
msg = str(time.time())
for sub in subscriptions[:]:
sub.put(payload)
gevent.spawn(notify)
return "OK"
Thanks for the tip. But on one of my configs (WinPython/Python 3.5.2) I had to slightly modify the payload formatting line to add utf-8 decoding:
payload = unquote(request.data.decode("utf-8").split('=')[1]).replace('+','')
Great, thank you! @asampat3090 @madi171
from urllib import unquote
that import was changed in the newest version of urllib to:
from urllib.parse import unquote