0

I'm trying to parse json data from the following website, and I'm getting the following error:

Error Type: <type 'exceptions.TypeError'>
Error Contents: unhashable type: 'list'
File "/....py", line 95, in <module>
['title']: post['title'],
TypeError: unhashable type: 'list'
-->End of Python script error report<--

My code is as follows, as you can see, I've tried to create a dict = but obviously I've not done it correctly. I understand the json data stuff needs to be added to a dictionary but I can't work out how to do this. Any help would be greatly appreciated.

def get_playable_podcast(soup):
    """
    @param: parsed html page            
    """
    data = []

r    = urllib.urlopen('https://thisiscriminal.com/wp-json/criminal/v1/episodes?posts=10000&page=1')
data = json.loads(r.read().decode('utf-8'))

my_dict = {'title': 'test1','episodeNumber': 'test2', 'audioSource': 'test3', 'image': 'test4', 'medium': 'test5'}

for post in data['posts']:

          print post['title']
          print post['episodeNumber']
          print post['audioSource']
          print post['image']['medium']
          print post['content'] ASCII encoding error

          item = {
                ['title']: post['title'],
                ['audioSource']: post['audioSource'],
                ['content']: desc,
                ['episodeNumber']: post['episodeNumber'],
                ['medium']: post['image']['medium']
        }

          data.append(item)

          print data
          print subjects

        #subjects.append(item)

        #print subjects
leopheard
  • 101
  • 7
  • Why are you trying to have a list as a key to `item`? Why not just `'title': post['title']` (and the same with other such lines)? Lists can't be keys. – Carcigenicate Jul 13 '19 at 00:26
  • @Carcigenicate Do you mean remove the 'dict =' line? I did and the error is now: Error Type: ['title']: post['title'], TypeError: unhashable type: 'list' – leopheard Jul 13 '19 at 00:31
  • No. Note how I removed the `[]` around `'title'`. Again, you can't have a list (`[]`) as the key to a dictionary like you have here. `['title']` is a list. – Carcigenicate Jul 13 '19 at 00:32
  • @Carcigenicate Aah, okay, that helped thanks yes. Only issue is that for some reason it's trying to treat the 'append' fuction as a list rather than function? Error: data.append(item) AttributeError: 'dict' object has no attribute 'append' – leopheard Jul 13 '19 at 00:36
  • Somewhere you're trying to call append on a dictionary. Without seeing the full error that's all I can say. Dictionaries don't have a append method. – Carcigenicate Jul 13 '19 at 00:41
  • @Carcigenicate This is the entire error: ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<-- Error Type: Error Contents: 'dict' object has no attribute 'append' Traceback (most recent call last): File "addon.py", line 6, in from resources.lib import thisiscriminal File "....py", line 102, in data.append(item) AttributeError: 'dict' object has no attribute 'append' >End of Python script error report<-- – leopheard Jul 13 '19 at 00:49
  • Full code in this pastebin: https://pastebin.com/Psnkvy26 – leopheard Jul 13 '19 at 00:50

0 Answers0