I'm writing a Python script that gets an HTTP request as its input (namely, a url and some GET parameters). The response to the HTTP request is a piece of Python code representing a big Python dictionary. My script should evaluate the retrieved code and process the evaluated dictionary.
Had I been using Python 2.X, I would have done the follwoing:
import urllib
d = eval(urllib.request.urlopen(input_url).read())
process(d)
The problem is that I'm using Python 3.4, and the read
method returns a bytes
and not a string
as in Python 2.X, so I can't use the eval
function on it.
How do I evaluate the retrieved dictionary on Python 3.X?