Commits

Anonymous committed a344882

完善WEB上传图片

Comments (0)

Files changed (1)

         u = self.request.get("u")
         des = self.request.get("des")
         name = self.request.get("name")
-        result = urlfetch.fetch(u)
-        if result.status_code == 200:
+        retries = 3
+        result = None
+        try:
+            result = urlfetch.fetch(u,deadline=10)
+        except:
+            retries -=1
+            if retries > 0:
+                result = urlfetch.fetch(u,deadline=10)
+            
+        if result and result.status_code == 200:
             album = Album.get_by_key_name(album)
             bf = result.content
             mime = getImageInfo(bf)[0]
                 raise Exception(u"不是正确的图片")
             img = Image.add(album,name,mime,bf,**{"description":des})
             self.redirect(album.m_url)
-            
+        else:
+            self.response.out.write(u"此地址抓取错误")
         
 class ImageDelHandler(AdminHandler):
     def get(self):