Commits

Stefan Scherfke  committed 0466fba

put try/except arount urlllib-statements

  • Participants
  • Parent commits fabf377
  • Tags v0.1.1

Comments (0)

Files changed (1)

File lastfm/views.py

         
     chart = chart_types[settings.LASTFM_CHART_TYPE]()
     
-    params = urllib.urlencode(chart.params)
-    data = json.loads(urllib.urlopen(url + params).read())
+    try:
+        params = urllib.urlencode(chart.params)
+        data = json.loads(urllib.urlopen(url + params).read())
+    except IOError:
+        return HttpResponse(json.dumps([]), mimetype='application/json')
     
     items = []
     for i, d in enumerate(chart.get_data(data)):
             'format': 'json',
         })
         
-        img_data = json.loads(urllib.urlopen(url + params).read())['images']
+        try:
+            img_data = json.loads(urllib.urlopen(url + params).read())['images']
+        except IOError:
+            return ''
         if 'image' in img_data:
             img_data = img_data['image']['sizes']['size']
             for img in img_data: