samsungctl: getting appdata TypeError: string indices must be integers

I was trying to pull back data for my apps and I kept getting:

Traceback (most recent call last):
  File "./samsung-test.py", line 17, in <module>
    for app in remote.applications:
  File "/usr/lib/python2.7/site-packages/samsungctl-0.8.0b-py2.7.egg/samsungctl/remote_websocket.py", line 227, in applications
    if app_1['appId'] == app_2['appId']:
TypeError: string indices must be integers

So I updated the code to resolve that issue:

for app_1 in app_data[1]['data']:
            for app_2 in app_data[0]:
                if str(app_1['appId']) == str(app_2['appId']):
                    app_1.update(app_2)

        res = []
        for app in app_data[1]:
            res += [application.Application(self, **app)]

but now I am getting this error:

Traceback (most recent call last):
  File "./samsung-test.py", line 17, in <module>
    for app in remote.applications:
  File "/usr/lib/python2.7/site-packages/samsungctl-0.8.0b-py2.7.egg/samsungctl/remote_websocket.py", line 232, in applications
    res += [application.Application(self, **app)]
TypeError: type object argument after ** must be a mapping, not unicode

NOTE: The line number is wrong in my error message because I added so many print statements to troubleshoot this.

I will admit that I am a bit of a hack when it comes to code, so I am not sure what the last error means or how to correct it. Any advice?

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 22 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I do not think what you gave for a PR is going to fix the issue.

reason why is I set up the containers that hold the application data as a list. and it is a list that get sent back from the TV. by placing the [‘data’] where you did is trying to access a list as a dictionary. I need to see the exact data that gets returned by the TV so we know what thee structure looks like exactly.

When I ran the script it pulled back and reported the information I expected to see. Here is the data before the change. In order for the loop to work I had to start the loop with data under the “data” key so it new where to get the “data”.

Here is what it returns:

    "data": [
        {
            "appId": "3201512006963", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201512006963/250x250.png", 
            "name": "Plex"
        }, 
        {
            "appId": "111012010001", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/111012010001/250x250.png", 
            "name": "VUDU"
        }, 
        {
            "appId": "111299001912", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/111299001912/250x250.png", 
            "name": "YouTube"
        }, 
        {
            "appId": "111199000417", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/111199000417/250x250.png", 
            "name": "HBO GO"
        }, 
        {
            "appId": "3201608010239", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201608010239/250x250.png", 
            "name": "TV Plus"
        }, 
        {
            "appId": "11101200001", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/11101200001/250x250.png", 
            "name": "Netflix"
        }, 
        {
            "appId": "3201606009872", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201606009872/250x250.png", 
            "name": "Emby"
        }, 
        {
            "appId": "3201601007625", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201601007625/250x250.png", 
            "name": "Hulu"
        }, 
        {
            "appId": "111399000031", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/111399000031/250x250.png", 
            "name": "FandangoNOW"
        }, 
        {
            "appId": "20162100005", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/20162100005/250x250.png", 
            "name": "e-Manual"
        }, 
        {
            "appId": "org.tizen.browser", 
            "app_type": 4, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/webbrowser/250x250.png", 
            "name": "Web Browser"
        }, 
        {
            "appId": "3201601007250", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201601007250/250x250.png", 
            "name": "Google Play Movies \uff06 TV"
        }, 
        {
            "appId": "11091000000", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/11091000000/250x250.png", 
            "name": "Facebook Watch"
        }, 
        {
            "appId": "3201512006785", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201512006785/250x250.png", 
            "name": "Amazon Video"
        }, 
        {
            "appId": "11101000410", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/11101000410/250x250.png", 
            "name": "Vimeo"
        }, 
        {
            "appId": "3201504002064", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201504002064/250x250.png", 
            "name": "GameFly Streaming"
        }, 
        {
            "appId": "3201606009840", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201606009840/250x250.png", 
            "name": "NBC"
        }, 
        {
            "appId": "3201611010963", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201611010963/250x250.png", 
            "name": "SHOWTIME"
        }, 
        {
            "appId": "3201608010450", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201608010450/250x250.png", 
            "name": "HGTV"
        }, 
        {
            "appId": "3201704012161", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201704012161/250x250.png", 
            "name": "CNNgo"
        }, 
        {
            "appId": "3201707014448", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201707014448/250x250.png", 
            "name": "Sling TV"
        }, 
        {
            "appId": "3201502001363", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201502001363/250x250.png", 
            "name": "iHeartRadio"
        }, 
        {
            "appId": "3201707014489", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201707014489/250x250.png", 
            "name": "YouTube TV"
        }, 
        {
            "appId": "3201708014637", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201708014637/250x250.png", 
            "name": "Freeform"
        }, 
        {
            "appId": "3201710014981", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201710014981/250x250.png", 
            "name": "CBS All Access"
        }, 
        {
            "appId": "3201711015155", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201711015155/250x250.png", 
            "name": "CBS News: Live Breaking News"
        }, 
        {
            "appId": "3201710014874", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201710014874/250x250.png", 
            "name": "Amazon Music"
        }, 
        {
            "appId": "3201608010313", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201608010313/250x250.png", 
            "name": "Food Network"
        }, 
        {
            "appId": "3201608010451", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201608010451/250x250.png", 
            "name": "Travel Channel"
        }, 
        {
            "appId": "3201506003227", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201506003227/250x250.png", 
            "name": "STARZ"
        }, 
        {
            "appId": "111199000333", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/111199000333/250x250.png", 
            "name": "UFC.TV"
        }, 
        {
            "appId": "3201608010191", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201608010191/250x250.png", 
            "name": "Deezer"
        }, 
        {
            "appId": "3201709014781", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201709014781/250x250.png", 
            "name": "Pantaya"
        }, 
        {
            "appId": "11091300004", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/11091300004/250x250.png", 
            "name": "Pandora"
        }, 
        {
            "appId": "3201702011851", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201702011851/250x250.png", 
            "name": "Steam Link"
        }, 
        {
            "appId": "121299000101", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/121299000101/250x250.png", 
            "name": "TuneIn"
        }, 
        {
            "appId": "3201801015541", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201801015541/250x250.png", 
            "name": "Discovery GO"
        }, 
        {
            "appId": "3201605009473", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201605009473/250x250.png", 
            "name": "NBC Sports"
        }, 
        {
            "appId": "3201608010240", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201608010240/250x250.png", 
            "name": "NFL SUNDAY TICKET"
        }, 
        {
            "appId": "3201806016508", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201806016508/250x250.png", 
            "name": "ABC"
        }, 
        {
            "appId": "3201806016390", 
            "app_type": 2, 
            "icon": "/opt/down/webappservice/apps_icon/FirstScreen/3201806016390/250x250.png", 
            "name": "DAZN"
        }
    ]
}