muh6mm3d / pylast

Automatically exported from code.google.com/p/pylast
Apache License 2.0
0 stars 0 forks source link

"NoneType object is unsubscriptable" Exception #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I'm getting a "NoneType object is unsubscriptable" error with multiple API 
methods 
(Album.getImage and Artist.getBioSummary).  I recently updated my copy of 
pylast from the 
alpha version from August 15th to the latest SVN version.  I didn't get this 
error when using the 
alpha code.

Here's the traceback I have for the error when using the getImage method.

Traceback:
File "/Users/brett/Workspace/Development/lastfm.py" in get_data
  137.      album.lf_image_url = lf_album.getImage(pylast.IMAGE_LARGE)
File "/Library/Python/2.5/site-packages/pylast.py" in getImage
  483.      return self._getCachedInfo()['images'][size]

Exception Type: TypeError
Exception Value: 'NoneType' object is unsubscriptable

I apologize if this is a bug in my code and not pylast.  I'm just getting 
started with Python, and I 
was really happy to find this library was available to save me the time of 
having to write my own.  
Thanks for posting your work, and I hope my bug report helps!

Original issue reported on code.google.com by codemo...@gmail.com on 21 Aug 2008 at 12:27

GoogleCodeExporter commented 9 years ago
Some more info: the album I looked up in the above case was not in the Last.fm 
database.  However, my code 
checks to see if the Album constructor returns None and doesn't try to get the 
image if that is the case.  So I 
think the problem is just that pylast isn't returning None when an album isn't 
found.  (Also the documentation 
doesn't mention what should be returned in that case either, so maybe that 
could be improved too.)

Original comment by codemo...@gmail.com on 21 Aug 2008 at 12:33

GoogleCodeExporter commented 9 years ago
yeah, actually pylast object don't check if the metdata exists on the last.fm 
servers
on construction. but an ServiceException is raised if an operation was 
attempted on a
non-existent object. of course, with the silent exception handling, you don't 
get to
see the exception, but you can check for it by calling object.last_error().
operations that fail always return None and raises an exception (silent or 
not), so
getImage() should return None if a ServiceException is raised because the album 
is
not on the server's database. i'll get on fixing that right away. i'll try to 
write
more on the silent exception handling in the wiki, it's just that documenting 
code is
pretty damn boring, i look for any excuse to get away from it. check the svn in 
the
next few minutes for an update. thanks for taking the time to report that..

Original comment by amr.hassan on 21 Aug 2008 at 8:34