-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: CaseInsensitiveDict is not JSON serializable #1380
Comments
While this is not actually requests bug, it does break some use cases prior to the introduction of CaseInsensitiveDict usage. |
This is easily worked around by doing: import requests
import json
r = requests.get(url)
headers_json = json.dumps(dict(r.headers)) Technically we could return any object that behaves like a dict without it being a dict, so I don't see this as much of a problem. What would be fantastic is if there were a I'll defer to @Lukasa on this one though. I personally don't find this so offensive frankly but I'm not against changing it either. |
Thank you @sigmavirus24. I'm aware of this workaround, I brought this up only because it broke existing code of mine (so possibly others' who haven't updated to 1.2.x). I'm 👍 for a |
Magic methods are so often nice. That's more of a pipe-dream than anything else. The stdlib |
I'm with @sigmavirus24 here. This is a pain, but the Case-Insensitive Dict is awesome. As for magic methods, I think JSON will never add one. JSON should be round-trippable, e.g: @woozyking, for what it's worth, if you find yourself doing this a lot, you can use a [custom JSON encoder with the Sorry that we caused you this inconvenience, but I think things are going to stay as they are. Thanks so much for raising the issue though! 🍰 |
@sigmavirus24 a quick test with the latest simplejson indicates that they don't have built-in resolution for this case. @Lukasa fully understand. |
@Lukasa that's true. But it would still be convenient. :-P |
The recent change that makes header case insensitive dict makes it impossible to dump request headers into a JSON object.
To reproduce this issue:
The text was updated successfully, but these errors were encountered: