本文整理汇总了Python中xmltojson.xmltojson函数的典型用法代码示例。如果您正苦于以下问题:Python xmltojson函数的具体用法?Python xmltojson怎么用?Python xmltojson使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmltojson函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: sendTemplateSMS
def sendTemplateSMS(self, to,datas,tempId):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/SMS/TemplateSMS?sig=" + sig
#生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
#创建包体
b=''
for a in datas:
b+='<data>%s</data>'%(a)
# body ='<?xml version="1.0" encoding="utf-8"?><TemplateSMS><datas>'+b+'</datas><to>%s</to><templateId>%s</templateId><appId>%s</appId>\
# </TemplateSMS>\
# '%(to, tempId,self.AppId)
body = '<?xml version="1.0" encoding="utf-8"?><TemplateSMS><datas>{}</datas><to>{}</to><templateId>{}</templateId><appId>{}</appId></TemplateSMS>'.format(b,to,tempId,self.AppId)
if self.BodyType == 'json':
# if this model is Json ..then do next code
b='['
for a in datas:
b+='"%s",'%(a)
b+=']'
body = '''{"to": "%s", "datas": %s, "templateId": "%s", "appId": "%s"}'''%(to,b,tempId,self.AppId)
req.add_header("Content-Length", len(body))
req.add_data(body)
data=''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType=='json':
#json格式
locations = json.loads(data)
else:
#xml格式
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:jinji-liuhai,项目名称:myproject,代码行数:53,代码来源:CCPRestSDK.py
示例2: landingCall
def landingCall(self, to, mediaName, mediaTxt, displayNum, playTimes, respUrl, userData, maxCallTime, speed, volume,
pitch, bgsound):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
# 生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
# 拼接URL
url = "https://" + self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/Calls/LandingCalls?sig=" + sig
# 生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
# 创建包体
body = '''<?xml version="1.0" encoding="utf-8"?><LandingCall>\
<to>%s</to><mediaName>%s</mediaName><mediaTxt>%s</mediaTxt><appId>%s</appId><displayNum>%s</displayNum>\
<playTimes>%s</playTimes><respUrl>%s</respUrl><userData>%s</userData><maxCallTime>%s</maxCallTime><speed>%s</speed>
<volume>%s</volume><pitch>%s</pitch><bgsound>%s</bgsound></LandingCall>\
''' % (
to, mediaName, mediaTxt, self.AppId, displayNum, playTimes, respUrl, userData, maxCallTime, speed, volume,
pitch, bgsound)
if self.BodyType == 'json':
body = '''{"to": "%s", "mediaName": "%s","mediaTxt": "%s","appId": "%s","displayNum": "%s","playTimes": "%s","respUrl": "%s","userData": "%s","maxCallTime": "%s","speed": "%s","volume": "%s","pitch": "%s","bgsound": "%s"}''' % (
to, mediaName, mediaTxt, self.AppId, displayNum, playTimes, respUrl, userData, maxCallTime, speed,
volume,
pitch, bgsound)
req.add_data(body)
data = ''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType == 'json':
# json格式
locations = json.loads(data)
else:
# xml格式
xtj = xmltojson()
locations = xtj.main(data)
if self.Iflog:
self.log(url, body, data)
return locations
except Exception, error:
if self.Iflog:
self.log(url, body, data)
return {'172001': '网络错误'}
开发者ID:Chenboxi2015,项目名称:iHome,代码行数:52,代码来源:CCPRestSDK.py
示例3: MediaFileUpload
def MediaFileUpload (self,filename,body):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/Calls/MediaFileUpload?sig=" + sig + "&appid=" + self.AppId + "&filename=" + filename
#生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
req.add_header("Authorization", auth)
if self.BodyType == 'json':
req.add_header("Accept", "application/json")
req.add_header("Content-Type", "application/octet-stream")
else:
req.add_header("Accept", "application/xml")
req.add_header("Content-Type", "application/octet-stream")
#创建包体
req.add_data(body)
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType=='json':
#json格式
locations = json.loads(data)
else:
#xml格式
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:EHelp,项目名称:2015-2016-Project,代码行数:48,代码来源:CCPRestSDK.py
示例4: voiceVerify
def voiceVerify(self, verifyCode, playTimes, to, displayNum, respUrl, lang, userData):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
# 生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
# 拼接URL
url = "https://" + self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/Calls/VoiceVerify?sig=" + sig
# 生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
# 创建包体
body = '''<?xml version="1.0" encoding="utf-8"?><VoiceVerify>\
<appId>%s</appId><verifyCode>%s</verifyCode><playTimes>%s</playTimes><to>%s</to><respUrl>%s</respUrl>\
<displayNum>%s</displayNum><lang>%s</lang><userData>%s</userData></VoiceVerify>\
''' % (self.AppId, verifyCode, playTimes, to, respUrl, displayNum, lang, userData)
if self.BodyType == 'json':
# if this model is Json ..then do next code
body = '''{"appId": "%s", "verifyCode": "%s","playTimes": "%s","to": "%s","respUrl": "%s","displayNum": "%s","lang": "%s","userData": "%s"}''' % (
self.AppId, verifyCode, playTimes, to, respUrl, displayNum, lang, userData)
req.add_data(body)
data = ''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType == 'json':
# json格式
locations = json.loads(data)
else:
# xml格式
xtj = xmltojson()
locations = xtj.main(data)
if self.Iflog:
self.log(url, body, data)
return locations
except Exception, error:
if self.Iflog:
self.log(url, body, data)
return {'172001': '网络错误'}
开发者ID:Chenboxi2015,项目名称:iHome,代码行数:48,代码来源:CCPRestSDK.py
示例5: billRecords
def billRecords(self,date,keywords):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/BillRecords?sig=" + sig
#生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
#创建包体
body ='''<?xml version="1.0" encoding="utf-8"?><BillRecords>\
<appId>%s</appId><date>%s</date><keywords>%s</keywords>\
</BillRecords>\
'''%(self.AppId,date,keywords)
if self.BodyType == 'json':
# if this model is Json ..then do next code
body = '''{"appId": "%s", "date": "%s","keywords": "%s"}'''%(self.AppId,date,keywords)
req.add_data(body)
data=''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType=='json':
#json格式
locations = json.loads(data)
else:
#xml格式
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:464647730,项目名称:CommunityHelp,代码行数:47,代码来源:CCPRestSDK.py
示例6: querySubAccount
def querySubAccount(self, friendlyName):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/QuerySubAccountByName?sig=" + sig
#生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
#创建包体
body ='''<?xml version="1.0" encoding="utf-8"?><SubAccount><appId>%s</appId>\
<friendlyName>%s</friendlyName>\
</SubAccount>\
'''%(self.AppId, friendlyName)
if self.BodyType == 'json':
body = '''{"friendlyName": "%s", "appId": "%s"}'''%(friendlyName,self.AppId)
data=''
req.add_data(body)
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType=='json':
#json格式
locations = json.loads(data)
else:
#xml格式
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:464647730,项目名称:CommunityHelp,代码行数:47,代码来源:CCPRestSDK.py
示例7: QueryCallState
def QueryCallState (self,callid,action):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/ivr/call?sig=" + sig + "&callid=" + callid
#生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
#创建包体
body ='''<?xml version="1.0" encoding="utf-8"?><Request>\
<Appid>%s</Appid><QueryCallState callid="%s" action="%s"/>\
</Request>\
'''%(self.AppId,callid,action)
if self.BodyType == 'json':
# if this model is Json ..then do next code
body = '''{"Appid":"%s","QueryCallState":{"callid":"%s","action":"%s"}}'''%(self.AppId,callid,action)
req.add_data(body)
data=''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType=='json':
#json格式
locations = json.loads(data)
else:
#xml格式
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:EHelp,项目名称:2015-2016-Project,代码行数:47,代码来源:CCPRestSDK.py
示例8: callBack
def callBack(self,fromPhone,to,customerSerNum,fromSerNum,promptTone,alwaysPlay,terminalDtmf,userData,maxCallTime,hangupCdrUrl,needBothCdr,needRecord,countDownTime,countDownPrompt):
self.subAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.SubAccountSid + self.SubAccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/SubAccounts/" + self.SubAccountSid + "/Calls/Callback?sig=" + sig
#生成auth
src = self.SubAccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
#创建包体
body ='''<?xml version="1.0" encoding="utf-8"?><CallBack>\
<from>%s</from><to>%s</to><customerSerNum>%s</customerSerNum><fromSerNum>%s</fromSerNum><promptTone>%s</promptTone><userData>%s</userData><maxCallTime>%s</maxCallTime><hangupCdrUrl>%s</hangupCdrUrl>\
<alwaysPlay>%s</alwaysPlay><terminalDtmf>%s</terminalDtmf><needBothCdr>%s</needBothCdr><needRecord>%s</needRecord><countDownTime>%s</countDownTime><countDownPrompt>%s</countDownPrompt>\
</CallBack>\
'''%(fromPhone,to,customerSerNum,fromSerNum,promptTone,userData,maxCallTime,hangupCdrUrl,alwaysPlay,terminalDtmf,needBothCdr,needRecord,countDownTime,countDownPrompt)
if self.BodyType == 'json':
body = '''{"from": "%s", "to": "%s","customerSerNum": "%s","fromSerNum": "%s","promptTone": "%s","userData": "%s","maxCallTime": "%s","hangupCdrUrl": "%s","alwaysPlay": "%s","terminalDtmf": "%s","needBothCdr": "%s","needRecord": "%s","countDownTime": "%s","countDownPrompt": "%s"}'''%(fromPhone,to,customerSerNum,fromSerNum,promptTone,userData,maxCallTime,hangupCdrUrl,alwaysPlay,terminalDtmf,needBothCdr,needRecord,countDownTime,countDownPrompt)
req.add_data(body)
data=''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType=='json':
#json格式
locations = json.loads(data)
else:
#xml格式
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:EHelp,项目名称:2015-2016-Project,代码行数:46,代码来源:CCPRestSDK.py
示例9: callBack
def callBack(self,fromPhone,to,customerSerNum,fromSerNum,promptTone):
self.subAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.SubAccountSid + self.SubAccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/SubAccounts/" + self.SubAccountSid + "/Calls/Callback?sig=" + sig
#生成auth
src = self.SubAccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
req.add_header("Authorization", auth)
#创建包体
body ='''<?xml version="1.0" encoding="utf-8"?><CallBack>\
<from>%s</from><to>%s</to><customerSerNum>%s</customerSerNum><fromSerNum>%s</fromSerNum><promptTone>%s</promptTone>\
</CallBack>\
'''%(fromPhone, to,customerSerNum,fromSerNum,promptTone)
if self.BodyType == 'json':
body = '''{"from": "%s", "to": "%s","customerSerNum": "%s","fromSerNum": "%s","promptTone": "%s"}'''%(fromPhone, to,customerSerNum,fromSerNum,promptTone)
req.add_data(body)
data=''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType=='json':
#json格式
locations = json.loads(data)
else:
#xml格式
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:464647730,项目名称:CommunityHelp,代码行数:45,代码来源:CCPRestSDK.py
示例10: ivrDial
def ivrDial(self,number,userdata,record):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/ivr/dial?sig=" + sig
#生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
req.add_header("Accept", "application/xml")
req.add_header("Content-Type", "application/xml;charset=utf-8")
req.add_header("Authorization", auth)
#创建包体
body ='''<?xml version="1.0" encoding="utf-8"?>
<Request>
<Appid>%s</Appid>
<Dial number="%s" userdata="%s" record="%s"></Dial>
</Request>
'''%(self.AppId,number,userdata,record)
req.add_data(body)
data=''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:464647730,项目名称:CommunityHelp,代码行数:40,代码来源:CCPRestSDK.py
示例11: queryAccountInfo
def queryAccountInfo(self):
self.accAuth()
nowdate = datetime.datetime.now()
self.Batch = nowdate.strftime("%Y%m%d%H%M%S")
#生成sig
signature = self.AccountSid + self.AccountToken + self.Batch;
sig = md5.new(signature).hexdigest().upper()
#拼接URL
url = "https://"+self.ServerIP + ":" + self.ServerPort + "/" + self.SoftVersion + "/Accounts/" + self.AccountSid + "/AccountInfo?sig=" + sig
#生成auth
src = self.AccountSid + ":" + self.Batch;
auth = base64.encodestring(src).strip()
req = urllib2.Request(url)
self.setHttpHeader(req)
body=''
req.add_header("Authorization", auth)
data=''
try:
res = urllib2.urlopen(req);
data = res.read()
res.close()
if self.BodyType=='json':
#json格式
locations = json.loads(data)
else:
#xml格式
xtj=xmltojson()
locations=xtj.main(data)
if self.Iflog:
self.log(url,body,data)
return locations
except Exception, error:
if self.Iflog:
self.log(url,body,data)
return {'172001':'网络错误'}
开发者ID:464647730,项目名称:CommunityHelp,代码行数:37,代码来源:CCPRestSDK.py
示例12: str_to_time
from datetime import datetime
def str_to_time(date_str):
""" converts the date string to datetime object """
date_fmt = "%a, %d %b %Y %H:%M:%S"
return datetime.strptime(date_str, date_fmt)
db.connect('sentinel')
class Report(db.Document):
""" a report document """
OWASPZAPReport = db.DynamicField()
def insert(self, json, collection='newreport'):
""" inserts the report to the database """
self.OWASPZAPReport= json['OWASPZAPReport']
self.switch_collection(collection)
self.save()
xmlreport = "full-report.xml"
json_report = xmltojson(xmlreport)
report = Report()
report_collection = 'ipc'
#report.insert(json_report, report_collection)
report.insert(json_report)
开发者ID:cshintov,项目名称:sentinel,代码行数:30,代码来源:reptomongo.py
注:本文中的xmltojson.xmltojson函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论