Python suds Exchange Web服务正在获取空服务属性

2024-05-15 23:59:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我终于让我的EWS客户不给我401个错误,但我不知道这是否意味着什么。现在当我实例化suds客户机对象时,它有一个空的服务属性。在

from suds.transport.https import *
from suds.client import Client 
from os import environ
import sys

def first(car=None, *cdr):
    return car

def cleaned(lines):
    return map(str.strip, lines)

def getauth(f=open("%s/.ews/auth"%(environ.get("HOME")), "rt")):
    return first(cleaned(f.readlines()), f.close())

def serviceURI():
    return "https://%s/ews/Services.wsdl"%(environ.get("WEBMAIL"))

def auth():
    def nclnt(tx):
        return Client(serviceURI(), transport=tx)
    def ntauth(username, password):
        '''Authenticate with NTLM and return the Client object.'''
        return nclnt(WindowsHttpAuthenticated(username=username,
                                              password=password))
    def webauth(username, password):
        '''Use standard web authentication.'''
        return nclnt(HttpAuthenticated(username=username,
                                       password=password))
    def authWith(method):
        return method(*getauth())
    return authWith(ntauth if "ntlm" in sys.argv else webauth)

def main():
    def _go(client):
        print client
        print client.last_received
        print dir(client.service)
        return 0
    return _go(auth())

if __name__=="__main__":
    main()

当我运行这个:

^{pr2}$

我注意到很多人抱怨这件事有问题,但还没有找到任何人声称已经让它发挥作用。在


Tags: fromimportclientauthreturnmaindefservice
1条回答
网友
1楼 · 发布于 2024-05-15 23:59:23

您的“print client”行没有返回任何内容,因此我怀疑wsdl有问题。 打开一些调试以查看发生了什么。。在

import logging
logging.basicConfig(level=logging.DEBUG, filename="suds.log")
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)

相关问题 更多 >