Я наконец-то заставил своего клиента 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()
И когда я запускаю это:
[ishpeck@slcyoshimitsu random_scripts]$ python ews.py ntlm
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913
<bound method Client.last_received of <suds.client.Client object at 0x17ea6d0>>
Traceback (most recent call last):
File "ews.py", line 42, in <module>
main()
File "ews.py", line 39, in main
return _go(auth())
File "ews.py", line 37, in _go
print dir(client.service)
File "/usr/lib/python2.7/site-packages/suds/client.py", line 296, in __getattr__
port = self.__find(0)
File "/usr/lib/python2.7/site-packages/suds/client.py", line 331, in __find
raise Exception, 'No services defined'
Exception: No services defined
[ishpeck@slcyoshimitsu random_scripts]$ python ews.py
Suds ( https://fedorahosted.org/suds/ ) version: 0.4 GA build: R699-20100913
<bound method Client.last_received of <suds.client.Client object at 0x136c6d0>>
Traceback (most recent call last):
File "ews.py", line 42, in <module>
main()
File "ews.py", line 39, in main
return _go(auth())
File "ews.py", line 37, in _go
print dir(client.service)
File "/usr/lib/python2.7/site-packages/suds/client.py", line 296, in __getattr__
port = self.__find(0)
File "/usr/lib/python2.7/site-packages/suds/client.py", line 331, in __find
raise Exception, 'No services defined'
Exception: No services defined
Я замечаю, что многие люди жалуются на проблемы с этой самой вещью, но не нашли никого, кто утверждал бы, что это заработало.