本文整理汇总了Python中openprovider.modules.E.username方法的典型用法代码示例。如果您正苦于以下问题:Python E.username方法的具体用法?Python E.username怎么用?Python E.username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openprovider.modules.E
的用法示例。
在下文中一共展示了E.username方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request
# 需要导入模块: from openprovider.modules import E [as 别名]
# 或者: from openprovider.modules.E import username [as 别名]
def request(self, tree, **kwargs):
"""
Construct a new request with the given tree as its contents, then ship
it to the OpenProvider API.
"""
apirequest = lxml.etree.tostring(
E.openXML(
E.credentials(
E.username(self.username),
OE('password', self.password),
OE('hash', self.password_hash),
),
tree
),
method='c14n'
)
try:
apiresponse = self.session.post(self.url, data=apirequest)
apiresponse.raise_for_status()
except requests.RequestException as e:
raise ServiceUnavailable(str(e))
tree = lxml.objectify.fromstring(apiresponse.content)
if tree.reply.code == 0:
return Response(tree)
else:
klass = from_code(tree.reply.code)
desc = tree.reply.desc
code = tree.reply.code
data = getattr(tree.reply, 'data', '')
raise klass(u"{0} ({1}) {2}".format(desc, code, data), code)