在 Python 中使用 Zimbra SOAP API
我正在尝试使用 Python 中的 Zimbra SOAP API 以编程方式修改 &清理我的联系人,但我在开始时遇到困难。
到目前为止我所得到的是:
from SOAPpy import SOAPProxy
url = 'https://zimbra/service/soap'
auth = {"account": "xxxxx", "password": "xxxxx"}
zimbra = SOAPProxy(url, 'urn:zimbra')
zimbraAuth = SOAPProxy(url, "urn:zimbraAccount")
zimbraMail = SOAPProxy(url, "urn:zimbraMail")
response = zimbraAuth.AuthRequest(**auth)
authToken = response.authToken
我已经成功登录,但无法在进一步的请求中传递此 authToken
。
我的理解是,任何 zimbraMail
请求都需要在 urn:zimbra
命名空间中有一个标头,并在那里设置 authToken,但对于 SOAP 来说,我不知道该怎么做所以。
我不喜欢使用 SOAPpy,因此任何其他库的示例代码将不胜感激。
I'm trying to use the Zimbra SOAP API from Python to programmatically modify & cleanup my contacts but I'm having trouble getting started.
What I have so far is:
from SOAPpy import SOAPProxy
url = 'https://zimbra/service/soap'
auth = {"account": "xxxxx", "password": "xxxxx"}
zimbra = SOAPProxy(url, 'urn:zimbra')
zimbraAuth = SOAPProxy(url, "urn:zimbraAccount")
zimbraMail = SOAPProxy(url, "urn:zimbraMail")
response = zimbraAuth.AuthRequest(**auth)
authToken = response.authToken
I've logged in successfully, but can't pass this authToken
in further requests.
My understanding is that any zimbraMail
requests need to have a header in the urn:zimbra
namespace with the authToken set there, but being new to SOAP I have no idea how to do so.
I'm not married to using SOAPpy so any example code for another library would be well appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想向 Python-Zimbra 的方向点头,这是一个 Zimbra 的 Python 库,这一切都会为您完成。
I'd like to nod in the direction of Python-Zimbra, a python library for Zimbra, which does all that for you.
还有一个更高级别的 Python 库:zimsoap。
使用原始 SOAP 或 python-zimbra 或 zimsoap 实际上取决于您需要什么级别的灵活性/易用性(尽管我不会建议直接使用 SOAP,因为 python-zimbra 可以向 zimbra 发出任何可能的 SOAP 请求。
There is also an higher level, and pythonic library: zimsoap.
Using raw SOAP or python-zimbra or zimsoap depends realy on what level of flexibility/ease you need (although I will not suggest using SOAP directly, as python-zimbra can issue any possible SOAP request to zimbra.