check regex match before access in flickr module
authorStefan Kögl <stefan@skoegl.net>
Thu, 19 Sep 2013 17:49:10 +0000 (19 19:49 +0200)
committerStefan Kögl <stefan@skoegl.net>
Thu, 19 Sep 2013 17:49:10 +0000 (19 19:49 +0200)
mygpo/data/flickr.py

index 2fde301..9506b00 100644 (file)
@@ -31,9 +31,11 @@ def get_photo_sizes(photo_id):
     resp = urllib.urlopen(request).read()
 
     extract_re = '^jsonFlickrApi\((.*)\)$'
-    resp_content = re.match(extract_re, resp).group(1)
+    m = re.match(extract_re, resp)
+    if not m:
+        return []
 
-    resp_obj = json.loads(resp_content)
+    resp_obj = json.loads(m.group(1))
 
     try:
         return resp_obj['sizes']['size']