简体   繁体   中英

Connecting to Microsoft Dynamics CRM 2011 SDK from Python

Has anyone had any luck connecting to the 2011 endpoints in Microsoft Dynamics CRM 2011 using Python? I've installed SUDS and can grab the WSDL, but service calls return 400 Bad Request. I'm sure it's because I'm not authenticated, but I'm not quite sure how to authenticate using raw SOAP. I know about Girish's code sample but am not familiar enough with SOAP to go much further.

I see this was asked a year ago on SO but that question seems to be about NTLM. In my case, I want to use WS-Trust.

Here is the code I've got:

from suds.client import Client
import logging

logging.basicConfig(level=logging.INFO)

url = 'https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc?wsdl'
client = Client(url)

req = client.factory.create('ns3:RetrieveOrganizationsRequest')
accessTypes = client.factory.create('ns3:AccessType')
orgRel = client.factory.create('ns3:OrganizationRelease')
req.AccessType = accessTypes.Default
req.Release = orgRel.Current

headers = dict()
headers['Content-Type'] = 'application/soap+xml'
client.set_options(headers=headers)

resp = client.service.Execute(req)

If using SOAP isn't a requirement -- consider the RESTish Odata service. I'm no Python expert -- but you could run through GET requests in a browser and use the debugger tools to see what the browser sends for headers and mimic this in your Python code. You'd have some choice over what format the service returns (JSON or XML) as well by modifying the Content-Type header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM