I took a long break from CS50, and came back to it today. I discovered that with no modifications and following the mashup directions, when running I always get an error on every method that returns jsonify(rows). The error is definitely on the call to jsonify, as I can print the rows before this line (so they are fetching from the DB correctly), and if I try to save to a variable (jsonResult = jsonify(rows)) it fails there instead of at the return line.

Here is the console messages (with my print line added right before jsonify):

INFO:werkzeug: - - [22/Dec/2017 21:22:31] "GET / HTTP/1.1" 200 -
INFO:werkzeug: - - [22/Dec/2017 21:22:31] "GET /jsglue.js HTTP/1.1" 200 -
DEBUG:cs50:SELECT * FROM places WHERE 37.35649690827123 <= latitude AND latitude <= 37.49064300835313 AND (-122.326694921875 <= longitude AND longitude <= -121.997105078125) GROUP BY country_code, place_name, admin_code1 ORDER BY RANDOM() LIMIT 10
[{'country_code': 'US', 'postal_code': '94028', 'place_name': 'Portola Valley', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'San Mateo', 'admin_code2': '081', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.3702, 'longitude': -122.2182, 'accuracy': 4}, {'country_code': 'US', 'postal_code': '94305', 'place_name': 'Stanford', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'Santa Clara', 'admin_code2': '085', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.4236, 'longitude': -122.1619, 'accuracy': 4}, {'country_code': 'US', 'postal_code': '94089', 'place_name': 'Sunnyvale', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'Santa Clara', 'admin_code2': '085', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.3983, 'longitude': -122.0006, 'accuracy': 4}, {'country_code': 'US', 'postal_code': '94043', 'place_name': 'Mountain View', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'Santa Clara', 'admin_code2': '085', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.4056, 'longitude': -122.0775, 'accuracy': 4}, {'country_code': 'US', 'postal_code': '94309', 'place_name': 'Palo Alto', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'Santa Clara', 'admin_code2': '085', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.4419, 'longitude': -122.143, 'accuracy': 4}, {'country_code': 'US', 'postal_code': '94023', 'place_name': 'Los Altos', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'Santa Clara', 'admin_code2': '085', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.3852, 'longitude': -122.1141, 'accuracy': 4}, {'country_code': 'US', 'postal_code': '94063', 'place_name': 'Redwood City', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'San Mateo', 'admin_code2': '081', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.4815, 'longitude': -122.2091, 'accuracy': 4}, {'country_code': 'US', 'postal_code': '94027', 'place_name': 'Atherton', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'San Mateo', 'admin_code2': '081', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.4563, 'longitude': -122.2002, 'accuracy': 4}, {'country_code': 'US', 'postal_code': '94025', 'place_name': 'Menlo Park', 'admin_name1': 'California', 'admin_code1': 'CA', 'admin_name2': 'San Mateo', 'admin_code2': '081', 'admin_name3': '', 'admin_code3': '', 'latitude': 37.4396, 'longitude': -122.1864, 'accuracy': 4}]
[2017-12-22 21:22:31,694] ERROR in app: Exception on /update [GET]
Traceback (most recent call last):
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ubuntu/workspace/pset8/mashup/application.py", line 90, in update
    jsonResponse = jsonify(rows)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/flask/json.py", line 251, in jsonify
    if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/werkzeug/local.py", line 347, in __getattr__
    return getattr(self._get_current_object(), name)
  File "/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/werkzeug/wrappers.py", line 689, in is_xhr
    ), stacklevel=2)
DeprecationWarning: Request.is_xhr is deprecated. Given that the X-Requested-With header is not a part of any spec, it is not reliable
INFO:werkzeug: - - [22/Dec/2017 21:22:31] "GET /update?ne=37.49064300835313%2C-121.997105078125&q=&sw=37.35649690827123%2C-122.326694921875 HTTP/1.1" 500 -

Even I'm facing similar kind of problem. It seems the flask itself has problem with jsonify.

Here is the link issue reported https://github.com/pallets/flask/issues/2549

Adding the following code in application.py will work.

# Disable pretty JSON
# https://github.com/pallets/flask/issues/2549

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .