stock quotes off the web, py style

Peter Otten __peter__ at web.de
Wed May 16 10:31:37 EDT 2018


Friedrich Rentsch wrote:

>  >>> ibm = urllib2.urlopen
> ("https://api.iextrading.com/1.0/stock/IBM/quote").read()
>  >>> ibm = eval (ibm)

Dont do this. You are allowing the guys at iextrading.com to execute 
arbitrary code on your machine. Use

    ibm = json.loads(ibm)

instead or 

    import urllib.request, json
    ibm = urllib.request.urlopen(
        "https://api.iextrading.com/1.0/stock/IBM/quote"
    ).read()
    ibm = json.loads(ibm.decode("utf-8"))

if you are using Python 3.





More information about the Python-list mailing list