When trying to convert a string to a dictionary, I get a type error NameError
because it contains values true
and false
with the first letter in lowercase.
I know that I can use it try exception
to work errors but I don't know how to modify the variables. How do I do in this case so that it capitalizes the first of the booleans?
try:
dicc = eval(response.text)
except NameError:
print('ERROR')
Where it response.text
comes from a request made with the bookstore requests
.
Thank you very much
I'm assuming you're getting a response in json format, not a python dictionary. It's better to use the appropriate module instead of
eval
:In addition, the response returned by the module's functions
requests
has a special methodjson()
:I would even advise you never to use
eval
, even if you really want to.Why is using 'eval' a bad practice?