Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError error and blank web while running with keras 1.2.1 #12

Open
madi171 opened this issue Feb 14, 2017 · 4 comments
Open

TypeError error and blank web while running with keras 1.2.1 #12

madi171 opened this issue Feb 14, 2017 · 4 comments

Comments

@madi171
Copy link

madi171 commented Feb 14, 2017

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

@asampat3090
Copy link

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"

blackccpie pushed a commit to blackccpie/hualos that referenced this issue Mar 13, 2017
@blackccpie
Copy link

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

@maximus009
Copy link

maximus009 commented Mar 20, 2017

Great, thank you!
@asampat3090 @madi171

MartinThoma added a commit to MLVis/hualos that referenced this issue Apr 5, 2017
@Eulenator
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants