NameError: name ‘null’ is not defined
When running the interface test script today, an error NameError was encountered: name ‘null’ is not defined. Cause: there is a null value when converting a string to a dictionary
ret = '{"createdAt":"","updatedAt":"", "dataSets":null}'
ret = eval(ret)
print(ret)
out:
ret = eval(ret)
File "<string>", line 1, in <module>
NameError: name 'null' is not defined
The solution is to use the JSON. Loads() function: convert the JSON format data into a dictionary. When there is null, it is converted to none
import json
ret = '{"createdAt":"","updatedAt":"", "dataSets":null}'
ret = json.loads(ret)
print(ret)
print(type(ret))
out:
{'createdAt': '', 'updatedAt': '', 'dataSets': None}
<class 'dict'>
Read More:
- Python error collection: NameError: name ‘numpy’ is not defined
- NameError: global name ‘***‘ is not defined [How to Solve]
- [Solved] Python serializate error: NameError: name ‘JSON’ is not defined
- Python parsing JSON Error: NameError: name ‘false’ is not defined
- [Solved] Tensorflow Error: NameError: name ‘layers‘ is not defined
- “NameError: name ‘re’ is not defined” [How to Solve]
- NameError: name “defaultParams“ is not defined [How to Solve]
- NameError: name ‘xrange‘ is not defined [How to Solve]
- NameError: name ‘_C‘ is not defined [How to Solve]
- Python+Selenium Error: AttributeError: ‘WebDriver‘ NameError: name ‘By‘ is not defined
- Crawler overtime error socket.timeout: timed out/NameError: name ‘socket‘ is not defined
- [Solved] selenium.common.exceptions.JavascriptException: Message: javascript error: windows is not defined
- The matching result of Python XPath is null
- [Solved] TypeError: Object of type ‘bytes’ is not JSON serializable
- TypeError: Decimal type object is not a JSON serialization solution
- “EncoderDecoder: ‘mit_b1 is not in the backbone registry‘“ [How to Solve]
- [Solved] ParserError: NULL byte detected. This byte cannot be processed in Python‘s native csv library
- [How to Solve] Python TypeError: ‘int‘ object is not subscriptable
- [Solved] Pylint Warning: An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)
- pandas.DataFrame() Initializes NULL Error: DataFrame [How to Solve]