add try catch with urllib2.urlopen
This commit is contained in:
@@ -247,7 +247,6 @@ class WebWeixin(object):
|
|||||||
|
|
||||||
def webwxgetcontact(self):
|
def webwxgetcontact(self):
|
||||||
SpecialUsers = self.SpecialUsers
|
SpecialUsers = self.SpecialUsers
|
||||||
print self.base_uri
|
|
||||||
url = self.base_uri + '/webwxgetcontact?pass_ticket=%s&skey=%s&r=%s' % (
|
url = self.base_uri + '/webwxgetcontact?pass_ticket=%s&skey=%s&r=%s' % (
|
||||||
self.pass_ticket, self.skey, int(time.time()))
|
self.pass_ticket, self.skey, int(time.time()))
|
||||||
dic = self._post(url, {})
|
dic = self._post(url, {})
|
||||||
@@ -1022,11 +1021,26 @@ 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))
|
||||||
response = urllib2.urlopen(request)
|
#print(url)
|
||||||
data = response.read()
|
#response = urllib2.urlopen(request)
|
||||||
if jsonfmt:
|
|
||||||
return json.loads(data, object_hook=_decode_dict)
|
try:
|
||||||
return data
|
response = urllib2.urlopen(request)
|
||||||
|
data = response.read()
|
||||||
|
if jsonfmt:
|
||||||
|
return json.loads(data, object_hook=_decode_dict)
|
||||||
|
return data
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
checksLogger.error('HTTPError = ' + str(e.code))
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
checksLogger.error('URLError = ' + str(e.reason))
|
||||||
|
except httplib.HTTPException, e:
|
||||||
|
checksLogger.error('HTTPException')
|
||||||
|
except Exception:
|
||||||
|
import traceback
|
||||||
|
checksLogger.error('generic exception: ' + traceback.format_exc())
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
def _xiaodoubi(self, word):
|
def _xiaodoubi(self, word):
|
||||||
url = 'http://www.xiaodoubi.com/bot/chat.php'
|
url = 'http://www.xiaodoubi.com/bot/chat.php'
|
||||||
|
|||||||
Reference in New Issue
Block a user