opening a url with urllib in python 3

后端 未结 5 658
我在风中等你
我在风中等你 2020-12-24 07:27

i\'m trying to open the URL of this API from the sunlight foundation and return the data from the page in json. this is the code Ive produced, minus the parenthesis around m

5条回答
  •  别那么骄傲
    2020-12-24 07:42

    You need to use from urllib.request import urlopen, also I suggest you use the with statement while opening a connection.

    from urllib.request import urlopen
    
    with urlopen("https://sunlightlabs.github.io/congress/legislators?api_key='(myapikey)") as conn:
        # dosomething
    

提交回复
热议问题