如何使用Python连接到Microsoft Dynamics CRM服务器?

问题描述:

Microsoft Dynamics CRM服务使用NTLM身份验证,这使使用suds从python进程连接到它变得有些复杂。我正在寻找一个代码示例,该示例将:

The Microsoft Dynamics CRM service uses NTLM authentication, which makes connecting to it from a python process using suds somewhat complicated. I'm looking for a code sample that will:


  1. 发送并​​接收来自 RetrieveAttributeRequest $的响应c $ c>

  2. 发送并​​接收来自 Execute 请求的响应。

  1. Send and receive the response from a RetrieveAttributeRequest
  2. Send and receive the response from an Execute request.

这必须使用Python 2.6或Python 2.7,而不是Python3。我已经有一个使用curl的有效实现来执行此操作,但在最佳情况下它是片状的,并且作为一部分我要在工具中进行其他一些工作,我想清理它并使它使用python / suds运行。

This must use Python 2.6 or Python 2.7, not Python 3. I already have a working implementation that uses curl to do this, but it's flaky at the best of times, and as part of some other work I have in this tool I'd like to clean it up and make it run using python/suds.

我知道这有点晚了,但希望对您有所帮助。

I know this is a bit late but hopefully it will help someone.

NTLM身份验证已添加到版本0.3.8

NTLM authentication was added to suds in version 0.3.8.

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)