AttributeError: 'NoneType' object has no attribute 'startswith'

Recently I developed a plugin and I'm a complete noob in Python, but it still kinda works, but some users get errors that I can not reproduce.

 

So, in my plugin I am creating a VideoClipObject and filling its arguments I pass thumb a url to the file, or a resource, to determine which is which i have this procedure:

def GetThumb(thumb = ''):
    if thumb.startswith('http'):
        return thumb
    elif thumb <> '':
        return R(thumb)
    else:
        return R('icon-default.png')

and then another procedure thats is repsosible for VideoClipObjects looks like that:

@route(PREFIX + '/createvideoclipobject')
def CreateVideoClipObject(url, title, thumb, container = False):
    vco = VideoClipObject(
        key = Callback(CreateVideoClipObject, url = url, title = title, thumb = thumb, container = True),
        url = url,
        title = title,
        thumb = GetThumb(thumb),
        items = [...]
    )
    ...

where thumb is a string argument with value like 'image.png' or 'http://somewhere.com/image.png' or just empty string ('').

 

Full source code is accessible on github.

 

Anyone has any ideas why is the error occurring?

2013-12-10 21:52:22,177 (130c) :  CRITICAL (core:561) - Exception (most recent call last):
  File "C:\Users\PlexServerUser\AppData\Local\Plex Media Server\Plug-ins\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\runtime.py", line 840, in handle_request
    result = f(**d)
  File "C:\Users\PlexServerUser\AppData\Local\Plex Media Server\Plug-ins\IPTV.bundle\Contents\Code\__init__.py", line 106, in CreateVideoClipObject
    thumb = GetThumb(thumb),
  File "C:\Users\PlexServerUser\AppData\Local\Plex Media Server\Plug-ins\IPTV.bundle\Contents\Code\__init__.py", line 157, in GetThumb
    if thumb.startswith('http'):
AttributeError: 'NoneType' object has no attribute 'startswith'

I recently ran into this. You have a pull that is returning a blank thumb and .startswith() will not work with a blank thumb. So you have to check for a thumb first and then do the .startswith(). I am not sure what you are trying to do with that middle command, but this would stop the error:

def GetThumb(thumb = ''):
    if thumb:
        if thumb.startswith('http'):
            return thumb
    else:
        return R('icon-default.png')

You can do that check (see if thumb is not None) and the check for the 'http' part in one 'if':

if thumb and thumb.startswith('http'):
    return thumb
...

Thank You very much!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.