This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2013年03月07日 12:06 by joepie91, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg183653 - (view) | Author: Sven Slootweg (joepie91) | Date: 2013年03月07日 12:06 | |
When faced with a subclass of int like a psutil constant (such as for process status), that actually returns a non-numeric string when used with str(), the JSON module will serialize it as a string without quotes. An example... Code (Python): [...] "key": psutil._common.constant(0, "value"), "otherkey": "real string" [...] Output (JSON): [...] "key": value, "otherkey": "real string" [...] Due to the missing quotes around 'value', the JSON data is corrupted. The cause appears to be that the JSON module, when faced with an int (or subclass thereof), will use the string representation in the serialized data, which would normally be the integer as a string. This example uses a psutil constant, but this would occur with any int subclass that doesn't return itself as string representation. I'm not entirely sure how to resolve this issue or whether it can be resolved at all, as all possible solutions appear to have negative side-effects for more common cases. I'd imagine that checking whether the resulting string is numeric, besides being error-prone, would also cause unreasonable overhead during serialization. |
|||
| msg183664 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2013年03月07日 14:17 | |
Right, the appropriate thing to do there is to write a custom encoder/decoder to handle those objects. json only automatically handles types that work like the fundamental types, and this is a good thing, security-wise :) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:42 | admin | set | github: 61579 |
| 2013年03月07日 14:17:34 | r.david.murray | set | status: open -> closed nosy: + r.david.murray messages: + msg183664 resolution: not a bug stage: resolved |
| 2013年03月07日 12:06:14 | joepie91 | create | |