import base64
import urllib2
class SGovToken():
TIME_OUT = 3600
LAST_UPDATE_TIME = ""
TOKEN = ''
def __init__(self, *args, **kwargs):
pass
def get_token_from_sgovernace(self,appid,appkey,url):
if not appid or not appkey:
return 'ERROE'
soap_env = '''
<applicationID>{0}</applicationID>
<credential>{1}</credential>
'''
appkey = base64.standard_b64decode(appkey)
soap_content = soap_env.format(appid,appkey)
resquest = urllib2.Request(url,soap_content)
resquest.add_header('SOPAACTION','getTokenByAPPCREdential')
try:
response = urllib2.urlopen(resquest)
except HTTPERROR as e:
pass
if response is not none:
resp_content = response.read()
return resp_content
现在的代码在python2中可以正常的获取到resp_content
....但是在python3中,将urllib2
改为urllib.request
却是报错的。urllib2.Request
的data参数也改为了bytes
类型!!!不知道哪里还有问题呢?
相关分类