Discussions
Issue with Bulk API using Python - Foot Traffic / Weekly Patterns
7 days ago by Dionne Mitcham
Hi,
I am having issues with bulk API download of the Foot Traffic/Weekly Patterns data using Python. Below is the code and the error I am getting. Please provide guidance on how to resolve this issue.
import deweydatapy as ddp
# Step 1. Import encessary packages. Designate the API Key and Product Path.
import deweydatapy as ddp
# API Key
apikey = "\<API_KEY>"
# Product path
pp\_ = "<https://api.deweydata.io/api/v1/external/data/fldr_bpyousrmfggrfubk">
# Step 2. Review the meta information of the data product:
meta = ddp.get_meta(apikey, pp_, print_meta = True) # returns a dataframe with meta information
# Step 3. Collect the list of files to download and store in a dataframe:
files_df = ddp.get_file_list(apikey, pp_,
start_date = '2018-01-01',
end_date = '2023-03-31',
print_info = True);
# ERROR in Step 3:
***
JSONDecodeError Traceback (most recent call last)
File ~\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\requests\\models.py:976, in Response.json(self, **kwargs)
975 try:
--> 976 return complexjson.loads(self.text, **kwargs)
977 except JSONDecodeError as e:
978 # Catch JSON-related errors and raise as requests.JSONDecodeError
979 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
File ~\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\json\_\_init\_\_.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, \*\*kw)
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return \_default_decoder.decode(s)
347 if cls is None:
File ~\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\json\\decoder.py:345, in JSONDecoder.decode(self, s, \_w)
341 """Return the Python representation of `s` (a `str` instance
342 containing a JSON document).
343
344 """
--> 345 obj, end = self.raw_decode(s, idx=\_w(s, 0).end())
346 end = \_w(s, end).end()
File ~\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\json\\decoder.py:363, in JSONDecoder.raw_decode(self, s, idx)
362 except StopIteration as err:
--> 363 raise JSONDecodeError("Expecting value", s, err.value) from None
364 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
JSONDecodeError Traceback (most recent call last)
Cell In[11], line 2
1 # Collect the list of files to download and store in a dataframe:
----> 2 files_df = ddp.get_file_list(apikey, pp_,
3 start_date = '2018-01-01',
4 end_date = '2023-03-31',
5 print_info = True);
File ~\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\deweydatapy\\download.py:240, in get_file_list(apikey, product_path, start_page, end_page, start_date, end_date, meta, print_info)
223 def get_file_list(apikey, product_path, start_page=1, end_page=float('inf'),
224 start_date=None, end_date=None,
225 meta=None,
226 print_info=True):
227 """
228 Collects the file list information from data server.
229
(...) 237 :return: A DataFrame object contains files information.
238 """
--> 240 files_df, selection_meta, pages_meta = get_file_list_full(apikey, product_path,
241 start_page, end_page,
242 start_date, end_date,
243 meta,
244 print_info)
246 return files_df
File ~\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\deweydatapy\\download.py:159, in get_file_list_full(apikey, product_path, start_page, end_page, start_date, end_date, meta, print_info)
156 print(response)
157 return None
--> 159 res_json = response.json()
160 if 'page' not in res_json:
161 print("Error in response.json")
File ~\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\requests\\models.py:980, in Response.json(self, **kwargs)
976 return complexjson.loads(self.text, **kwargs)
977 except JSONDecodeError as e:
978 # Catch JSON-related errors and raise as requests.JSONDecodeError
979 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 980 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
# Step 4 - Download files from the dataframe (code fails before making it here):
ddp.download_files(files_df, "dewey-downloads/", skip_exists = True)