diff --git a/libsaria/lastfm.py b/libsaria/lastfm.py index 58cad943..f3fd4935 100644 --- a/libsaria/lastfm.py +++ b/libsaria/lastfm.py @@ -29,6 +29,8 @@ class LastFmRequest(dict): for param in self: url[param] = self[param] file = url.open() + if file == None: + return None if printfile==True: self.print_file(file) doc = xm.parse( file ) @@ -43,6 +45,8 @@ def lfm_cache_album(file, artist, album): req["album"] = album req["artist"] = artist doc = req.place() + if doc == None: + return False node = pref_attr(doc, "image", "size", pref_sizes) node = xm.child(node) if node == None: diff --git a/libsaria/web.py b/libsaria/web.py index 0c9a3997..6d73d5af 100644 --- a/libsaria/web.py +++ b/libsaria/web.py @@ -6,9 +6,10 @@ import string HEADER = libsaria.__vers__ -vals = [ ('%','25'), (' ','20'), ('&','26'), ('<','3C'), ('>','3E'), - ('"','22'), ('#','23'), ('$','24'), ('\'','27'), ('+','2B'), - (',','2C'), ('/','2F'), (':','3A'), ('[','5B'), (']','5D')] +#vals = [ ('%','25'), (' ','20'), ('&','26'), ('<','3C'), ('>','3E'), +# ('"','22'), ('#','23'), ('$','24'), ('\'','27'), ('+','2B'), +# (',','2C'), ('/','2F'), (':','3A'), ('[','5B'), (']','5D')] +vals = [ (' ','20'), ('&','26') ] class Url: @@ -20,10 +21,14 @@ class Url: self.url += "&" + key + "=" + value def open(self): - #print self.url - req = urllib2.Request(self.url) - req.add_header('User-Agent', HEADER) - return urllib2.urlopen(req) + print self.url + try: + req = urllib2.Request(self.url) + req.add_header('User-Agent', HEADER) + return urllib2.urlopen(req) + except Exception, e: + print e + return None def escape(string):