如何使用Python连接到微软Dynamics CRM服务器?
微软的Dynamics CRM服务使用NTLM认证,这让我们用Python的suds库连接起来有点复杂。我在找一个代码示例,能够做到以下两点:
- 发送并接收来自
RetrieveAttributeRequest
的响应。 - 发送并接收来自
Execute
请求的响应。
这个示例必须使用Python 2.6或2.7,而不是Python 3。我已经有一个用curl实现的工作代码,但它在很多时候都不太稳定。现在我想把它整理一下,改用Python和suds来运行。
2 个回答
0
我不知道这对你是否有帮助,但我用过 PycURL 来通过一个 NTLM 代理。
下面是一个代码片段:
c = Curl()
c.setopt(URL, 'http://www.somesite.com')
c.setopt(FOLLOWLOCATION, 1) # follow redirects
c.setopt(MAXREDIRS, 5) # max redirects
c.setopt(PROXY, 'proxy.somesite.com')
c.setopt(PROXYUSERPWD, 'DOMAIN/USER:PASSWORD')
c.setopt(PROXYAUTH, HTTPAUTH_NTLM) # use NTLM
c.perform()
这是关于 Curl
对象的 文档。
5
我知道这个回答有点晚,但希望能帮到某个人。
NTLM认证是在
from suds.transport.https import WindowsHttpAuthenticated
from suds.client import Client
url = 'http://crmurl/XRMServices/2011/Discovery.svc?wsdl'
ntlm = WindowsHttpAuthenticated(username='DOMAIN\username', password='password')
client = Client(url, transport=ntlm)