Pregunta

Are there any simple Heroku tutorials using Requests JSON?

Heroku is throwing dependency errors when my app.py calls another python script that using Request's json().

Heroku Logs is:

2014-03-11T17:56:57.518693+00:00 app[web.1]: 2014-03-11 17:56:57 [7] [ERROR] Error handling request
2014-03-11T17:56:57.518693+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 125, in handle_request
2014-03-11T17:56:57.518693+00:00 app[web.1]: Traceback (most recent call last):
2014-03-11T17:56:57.518693+00:00 app[web.1]:     respiter = self.wsgi(environ, resp.start_response)
2014-03-11T17:56:57.518693+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
2014-03-11T17:56:57.518693+00:00 app[web.1]:     response = self.full_dispatch_request()
2014-03-11T17:56:57.518693+00:00 app[web.1]:     response = self.make_response(self.handle_exception(e))
2014-03-11T17:56:57.518965+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
2014-03-11T17:56:57.518693+00:00 app[web.1]:     return self.wsgi_app(environ, start_response)
2014-03-11T17:56:57.518693+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
2014-03-11T17:56:57.518693+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
2014-03-11T17:56:57.518965+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
2014-03-11T17:56:57.518965+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2014-03-11T17:56:57.518965+00:00 app[web.1]:   File "/app/app.py", line 66, in processData
2014-03-11T17:56:57.518965+00:00 app[web.1]:     latAndLong = getLatLong.getLatLong(str(request.form.get('city')))
2014-03-11T17:56:57.518965+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
2014-03-11T17:56:57.518965+00:00 app[web.1]:     return self.view_functions[rule.endpoint](**req.view_args)
2014-03-11T17:56:57.518965+00:00 app[web.1]:     rv = self.dispatch_request()
2014-03-11T17:56:57.518965+00:00 app[web.1]:     myfile = r.get_json()
2014-03-11T17:56:57.519151+00:00 app[web.1]: AttributeError: 'Response' object has no attribute 'get_json'
2014-03-11T17:56:57.518965+00:00 app[web.1]:   File "/app/getLatLong.py", line 16, in getLatLong
2014-03-11T17:56:57.519447+00:00 heroku[router]: at=info method=POST path=/getsurveyresults host=censusmappingandmarketing.herokuapp.com request_id=1606f734-83bc-4d9c-a6af-8149e0f200e2 fwd="208.91.53.169" dyno=web.1 connect=1ms service=178ms status=500 bytes=238

The code it is having issue with is this:

r = requests.get(link)
myfile = r.json()

which is confusing because it works fine locally.

¿Fue útil?

Solución

This had a really stupid solution. I had to import requests in my requirements.txt. That was why it wasn't recognizing json() (since it was a requests function).

My requirements.txt now looks like:

Flask==0.9
Jinja2==2.6
Werkzeug==0.8.3
gunicorn==0.17.2
requests==2.2.1
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top