Code for bulk delete via API throwing JSON TypeError

The code for deleting all data shown at https://plot.ly/python/delete-plots/#delete-all-plots-and-grids-permanently throws a JSON Type error:

TypeError: the JSON object must be str, not 'bytes'

This seems to occur at json.loads in that code’s get_pages() function. Full traceback below; any advice much appreciated.

TypeError                                 Traceback (most recent call last)
<ipython-input-87-a6c7e7880633> in <module>
     45                     requests.delete('https://api.plot.ly/v2/files/'+fid+'/permanent_delete', auth=auth, headers=headers)
     46 
---> 47 permanently_delete_files(str(username), filetype_to_delete='plot')
     48 permanently_delete_files(str(username), filetype_to_delete='grid')

<ipython-input-87-a6c7e7880633> in permanently_delete_files(username, page_size, filetype_to_delete)
     32 
     33 def permanently_delete_files(username, page_size=500, filetype_to_delete='plot'):
---> 34     for page in get_pages(username, page_size):
     35         for x in range(0, len(page['children']['results'])):
     36             fid = page['children']['results'][x]['fid']

<ipython-input-87-a6c7e7880633> in get_pages(username, page_size)
     19     if response.status_code != 200:
     20         return
---> 21     page = json.loads(response.content)
     22     yield page
     23     while True:

/usr/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    310     if not isinstance(s, str):
    311         raise TypeError('the JSON object must be str, not {!r}'.format(
--> 312                             s.__class__.__name__))
    313     if s.startswith(u'\ufeff'):
    314         raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",

TypeError: the JSON object must be str, not 'bytes'