Skip to content

Commit

Permalink
try处理request超时的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
chliny committed May 1, 2014
1 parent 79a9f52 commit 101a35b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions xfdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,20 @@ def __request(self,url,data=None,savecookie=False):
"""
请求url
"""
if data:
data = parse.urlencode(data).encode('utf-8')
fp=request.urlopen(url,data)
else:
fp=request.urlopen(url)
istr = ''
try:
str = fp.read().decode('utf-8')
if data:
data = parse.urlencode(data).encode('utf-8')
fp=request.urlopen(url,data)
else:
fp=request.urlopen(url)
try:
istr = fp.read().decode('utf-8')

except UnicodeDecodeError:
str = fp.read()
except UnicodeDecodeError:
istr = fp.read()
except:
return False

if savecookie == True:
if hasattr(self,"pswd"):
Expand All @@ -150,7 +154,7 @@ def __request(self,url,data=None,savecookie=False):
self.cookieJar.save(ignore_discard=True, ignore_expires=True)

fp.close()
return str
return istr
def __getverifycode(self):

urlv = 'http://check.ptlogin2.qq.com/check?uin=%s&appid=567008010&r=%s'%(self.__qq,random.Random().random())
Expand Down

0 comments on commit 101a35b

Please # to comment.