本文整理匯總了Python中openprovider.modules.E.credentials方法的典型用法代碼示例。如果您正苦於以下問題:Python E.credentials方法的具體用法?Python E.credentials怎麽用?Python E.credentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類openprovider.modules.E
的用法示例。
在下文中一共展示了E.credentials方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: request
# 需要導入模塊: from openprovider.modules import E [as 別名]
# 或者: from openprovider.modules.E import credentials [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)