_get add try except
This commit is contained in:
@@ -1009,10 +1009,21 @@ class WebWeixin(object):
|
|||||||
request.add_header('Range', 'bytes=0-')
|
request.add_header('Range', 'bytes=0-')
|
||||||
if api == 'webwxgetvideo':
|
if api == 'webwxgetvideo':
|
||||||
request.add_header('Range', 'bytes=0-')
|
request.add_header('Range', 'bytes=0-')
|
||||||
|
try:
|
||||||
response = urllib2.urlopen(request)
|
response = urllib2.urlopen(request)
|
||||||
data = response.read()
|
data = response.read()
|
||||||
logging.debug(url)
|
logging.debug(url)
|
||||||
return data
|
return data
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
logging.error('HTTPError = ' + str(e.code))
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
logging.error('URLError = ' + str(e.reason))
|
||||||
|
except httplib.HTTPException, e:
|
||||||
|
logging.error('HTTPException')
|
||||||
|
except Exception:
|
||||||
|
import traceback
|
||||||
|
logging.error('generic exception: ' + traceback.format_exc())
|
||||||
|
return ''
|
||||||
|
|
||||||
def _post(self, url, params, jsonfmt=True):
|
def _post(self, url, params, jsonfmt=True):
|
||||||
if jsonfmt:
|
if jsonfmt:
|
||||||
@@ -1021,8 +1032,7 @@ class WebWeixin(object):
|
|||||||
'ContentType', 'application/json; charset=UTF-8')
|
'ContentType', 'application/json; charset=UTF-8')
|
||||||
else:
|
else:
|
||||||
request = urllib2.Request(url=url, data=urllib.urlencode(params))
|
request = urllib2.Request(url=url, data=urllib.urlencode(params))
|
||||||
#print(url)
|
|
||||||
#response = urllib2.urlopen(request)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = urllib2.urlopen(request)
|
response = urllib2.urlopen(request)
|
||||||
|
|||||||
Reference in New Issue
Block a user