If hasattr(urlResponse. Using requests would avoid all this, but sometimes you need to stick to the standard library. The headers object is different between Python 2 and 3 so it has to be done different ways. In this example we query the headers for the encoding and fall back to utf-8 if we don't get one. So one has to get the file encoding in order to make it work in Python 3. Ask Question Asked 2 years, 11 months ago. how to download JSON file using Python from a URL with authentication key. json.loads requires a string object and the output of urllib.urlopen(url).read() is a bytes object. I am trying to download JSON files from a website that is being accessed with username and password (API service). json.load is just a wrapper around json.loads that calls read() for a file-like object. Unfortunately, that doesn't work in Python 3. In Python 2, json.load() will work instead of json.loads() import json
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |