hualos icon indicating copy to clipboard operation
hualos copied to clipboard

TypeError error and blank web while running with keras 1.2.1

Open madi171 opened this issue 8 years ago • 4 comments

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

madi171 avatar Feb 14 '17 08:02 madi171

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"

asampat3090 avatar Mar 05 '17 08:03 asampat3090

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('+','')

blackccpie avatar Mar 20 '17 13:03 blackccpie

Great, thank you! @asampat3090 @madi171

maximus009 avatar Mar 20 '17 14:03 maximus009

from urllib import unquote that import was changed in the newest version of urllib to: from urllib.parse import unquote

Eulenator avatar Jun 05 '17 18:06 Eulenator