Python urllib2: Receive JSON response from url

后端 未结 10 2040
轮回少年
轮回少年 2020-11-29 17:22

I am trying to GET a URL using Python and the response is JSON. However, when I run

import urllib2
response = urllib2.urlopen(\'https://api.instagram.com/v1/         


        
10条回答
  •  醉酒成梦
    2020-11-29 18:07

    None of the provided examples on here worked for me. They were either for Python 2 (uurllib2) or those for Python 3 return the error "ImportError: No module named request". I google the error message and it apparently requires me to install a the module - which is obviously unacceptable for such a simple task.

    This code worked for me:

    import json,urllib
    data = urllib.urlopen("https://api.github.com/users?since=0").read()
    d = json.loads(data)
    print (d)
    

提交回复
热议问题