0

I'm relatively new to python and I'm trying to get to grips with jsonify within flask. I've looked at some basic online examples and tried to replicate:-

@app.route('/json')
def getjson():
  info = {
      'yes':'success',
      'at last':'it works'
  }
  return jsonify(info)

When I try to access /json I get an error:-

AttributeError: 'Request' object has no attribute 'is_xhr'

This is beyond me and I'm not sure where to start in debugging. ANy help would be appreciated.

full code

# Import the Flask class form the flask module
from flask import Flask, jsonify


# create the application object based on Flask class
appjson= Flask(__name__)

@appjson.route('/json')
def getjson():
    info = {
        'yes':'success',
        'at last':'it works'
        }
    return jsonify(info)



# start the server with the run() method
if __name__ =='__main__':
    appjson.run(debug=True)
  • Can you post the full error traceback? – SuperStormer Mar 14 '21 at 01:05
  • Can you show your package versions by showing the output of `pip list` ? This answer looks promising. https://stackoverflow.com/a/65684861/1457269 – ApplePie Mar 14 '21 at 01:06
  • 1
    Does this answer your question? [Weird "is\_xhr" error when deploying Flask app to Heroku](https://stackoverflow.com/questions/60131900/weird-is-xhr-error-when-deploying-flask-app-to-heroku) – SuperStormer Mar 14 '21 at 01:09
  • Thanks for the help. It seems the issues were to do with the early package versions of Flask and incompatibilities with dependent modules. Upgraded to Flask 1.1.0 and all working fine now. – Mark Phillips Mar 14 '21 at 21:28

0 Answers0