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

"Request.is_xhr deprecated" warning during jsonify() #2549

Closed
simlu opened this issue Dec 11, 2017 · 11 comments
Closed

"Request.is_xhr deprecated" warning during jsonify() #2549

simlu opened this issue Dec 11, 2017 · 11 comments
Labels

Comments

@simlu
Copy link

simlu commented Dec 11, 2017

It seems Request.is_xhr is deprecated. Getting warnings here... How do we fix this?

flask.jsonify(**{...})
File "/usr/local/lib/python2.7/site-packages/flask/json.py", line 251, in jsonify
if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
File "/usr/local/lib/python2.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
File "/usr/local/lib/python2.7/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
@ThiefMaster
Copy link
Member

ThiefMaster commented Dec 11, 2017

That depends on what you are using it for. And since this is not a place to ask for help but an issue tracker, please ask this question in the #pocoo IRC channel on freenode or on Stack Overflow.

@simlu
Copy link
Author

simlu commented Dec 11, 2017

@ThiefMaster Maybe I didn't make myself clear here. This is an issue with Flask. It should not be accessing Request.is_xhr. So this needs fixing so that Flask does not access Request.is_xhr.

Or am I totally misunderstanding?

@ThiefMaster ThiefMaster reopened this Dec 11, 2017
@ThiefMaster
Copy link
Member

Oh indeed, I didn't notice it's coming from within Flask. As a workaround on your side, simply disable JSONIFY_PRETTYPRINT_REGULAR or ignore the warning for now.

@ThiefMaster ThiefMaster changed the title Fix needed: Request.is_xhr deprecated "Request.is_xhr deprecated" warning during jsonify() Dec 11, 2017
@davidism
Copy link
Member

Master already removed this.

@simlu
Copy link
Author

simlu commented Dec 11, 2017

Sweet, thank you!

@KoJoVe
Copy link

KoJoVe commented Apr 4, 2018

/home/vicente/.local/lib/python3.6/site-packages/werkzeug/local.py:347: DeprecationWarning: Request.is_xhr is deprecated. Given that the X-Requested-With header is not a part of any spec, it is not reliable return getattr(self._get_current_object(), name)

Still getting this when using jsonify with flask, with python 3.6 :(
Anyone having the same issue?

@lafrech
Copy link

lafrech commented Apr 5, 2018

@KoJoVe this was fixed in master but there was no release since. Until next Flask version is released, you may disable JSONIFY_PRETTYPRINT_REGULAR as a workaround as suggested above.

@KoJoVe
Copy link

KoJoVe commented Apr 5, 2018

Oh, I did not understood that there was no releases since then. Thank you very much!

@AndySeymour2904
Copy link

This now completely breaks for me using 0.10.1 Flask (as of today). 0.12.4 did have the option of disabling request.is_xhr through the JSONIFY_PRETTYPRINT_REGULAR.

Complete error for other poor souls who might eventually get here like I did;

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

@ashishbainade-ekryp
Copy link

@AndySeymour2904 I am using the same version as you,
I Fixed using workaround not a permanent fix.
Its breaking at the line in file lib/python3.8/site-packages/flask/json.py
if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:

The request.is_xhr is not present & giving trouble.

Just set value of JSONIFY_PRETTYPRINT_REGULAR = False
So it will not go in AND condition itself.

@HackToHell
Copy link

HackToHell commented Feb 7, 2020

The problem is because flask doesn't lock it's dependencies. https://github.com/pallets/flask/blob/0.12.x/setup.py#L74 It installs Werkzeug>=0.7 and Wekzeug 1.0(released today, Feb 7) removes this function. Fix is to add Werkzeug==0.16.1 to your requirements.txt

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

No branches or pull requests

8 participants