2013-12-09 22 views
5

voglio usare Microsoft CRM webservice, ho provato questo codice:Connetti a Dynamics CRM con acqua e pitone

wsdl_url = 'http://crm-test:5555/CRMDeveleopment/XRMServices/2011/Organization.svc?wsdl' 
username = 'user' 
password = 'pass' 

from suds.transport.https import WindowsHttpAuthenticated 
from suds.client import Client 

import logging 
logging.basicConfig(level=logging.INFO) 
logging.getLogger('suds.client').setLevel(logging.DEBUG) 
logging.getLogger('suds.transport').setLevel(logging.DEBUG) 

ntlmTransport = WindowsHttpAuthenticated(username=username, password=password) 
metadata_client = Client(wsdl_url, transport=ntlmTransport, cache=None) 

ed ottengo questo errore:

Traceback (most recent call last): 
    File "crm.py", line 15, in <module> 
    metadata_client = Client(wsdl_url, transport=ntlmTransport) 
    File "/usr/lib/python2.7/site-packages/suds/client.py", line 112, in __init__ 
    self.wsdl = reader.open(url) 
    File "/usr/lib/python2.7/site-packages/suds/reader.py", line 152, in open 
    d = self.fn(url, self.options) 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 157, in __init__ 
    self.open_imports() 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 202, in open_imports 
    imp.load(self) 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 314, in load 
    d = Definitions(url, options) 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 159, in __init__ 
    self.build_schema() 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 220, in build_schema 
    self.schema = container.load(self.options) 
    File "/usr/lib/python2.7/site-packages/suds/xsd/schema.py", line 95, in load 
    child.dereference() 
    File "/usr/lib/python2.7/site-packages/suds/xsd/schema.py", line 323, in dereference 
    midx, deps = x.dependencies() 
    File "/usr/lib/python2.7/site-packages/suds/xsd/sxbasic.py", line 469, in dependencies 
    raise TypeNotFound(self.ref) 
suds.TypeNotFound: Type not found: '(ManagedPropertyAttributeRequiredLevel, http://schemas.microsoft.com/xrm/2011/Contracts,)' 

uscita per l'organizzazione

from suds import WebFault 
from suds.client import * 
from suds.transport.https import WindowsHttpAuthenticated 

user = r'domain.net\username' 
password = "password" 
url = "http://crm-test:5555/XRMServices/2011/Organization.svc?wsdl" 


ntlm = WindowsHttpAuthenticated(username = user, password = password) 
client = Client(url, transport=ntlm) 
print client 

errore:

$ python organization.py 
DEBUG:suds.transport.http:opening (http://crm-test.kavatelecom.net:5555/XRMServices/2011/Organization.svc?wsdl) 
DEBUG:suds.transport.http:opening (http://crm-test.kavatelecom.net:5555/XRMServices/2011/Organization.svc?wsdl=wsdl0) 
Traceback (most recent call last): 
    File "organization.py", line 15, in <module> 
    client = Client(url, transport=ntlm) 
    File "/usr/lib/python2.7/site-packages/suds/client.py", line 112, in __init__ 
    self.wsdl = reader.open(url) 
    File "/usr/lib/python2.7/site-packages/suds/reader.py", line 152, in open 
    d = self.fn(url, self.options) 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 157, in __init__ 
    self.open_imports() 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 202, in open_imports 
    imp.load(self) 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 314, in load 
    d = Definitions(url, options) 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 159, in __init__ 
    self.build_schema() 
    File "/usr/lib/python2.7/site-packages/suds/wsdl.py", line 220, in build_schema 
    self.schema = container.load(self.options) 
    File "/usr/lib/python2.7/site-packages/suds/xsd/schema.py", line 95, in load 
    child.dereference() 
    File "/usr/lib/python2.7/site-packages/suds/xsd/schema.py", line 323, in dereference 
    midx, deps = x.dependencies() 
    File "/usr/lib/python2.7/site-packages/suds/xsd/sxbasic.py", line 469, in dependencies 
    raise TypeNotFound(self.ref) 
suds.TypeNotFound: Type not found: '(ManagedPropertyAttributeRequiredLevel, http://schemas.microsoft.com/xrm/2011/Contracts,)' 
+0

Pensi di poter seguire questo post? Il passaggio a SOAP 1.1 ha risolto il problema? –

+0

vuoi dire che devo usare la versione precedente di suds? – nim4n

+0

È possibile pubblicare l'output da http: // crm-test: 5555/CRMDeveleopment/XRMServices/2011/Organization.svc? Wsdl –

risposta

2

mi collego a crm web service.but ottengo l'errore "" 400, u'Bad Request "" "quando eseguo le mie richieste!

il mio codice è:

from suds import WebFault 
from suds.client import * 
from suds.transport.https import WindowsHttpAuthenticated 
import logging 
logging.basicConfig(level=logging.INFO) 
logging.getLogger('suds.transport.http').setLevel(logging.DEBUG) 
user = r'domain\username' 
password = "pass" 
url = "http://domain:5555/XRMServices/2011/Discovery.svc?wsdl" 

ntlm = WindowsHttpAuthenticated(username = user, password = password) 
client = Client(url, transport=ntlm) 
print client 
req = client.factory.create('ns3:RetrieveOrganizationsRequest') 

accessTypes = client.factory.create('ns3:EndpointAccessType') 
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) 

l'uscita del client di stampa:

$ python newcrm.py 

Suds (https://fedorahosted.org/suds/) version: 0.4 GA build: R699-20100913 

Service (DiscoveryService) tns="http://schemas.microsoft.com/xrm/2011/Contracts" 
    Prefixes (4) 
     ns0 = "http://schemas.datacontract.org/2004/07/System.Collections.Generic" 
     ns1 = "http://schemas.microsoft.com/2003/10/Serialization/" 
     ns2 = "http://schemas.microsoft.com/xrm/2011/Contracts" 
     ns3 = "http://schemas.microsoft.com/xrm/2011/Contracts/Discovery" 
    Ports (1): 
     (CustomBinding_IDiscoveryService) 
     Methods (1): 
      Execute(ns3:DiscoveryRequest request,) 
     Types (24): 
      BaseServiceFault 
      ns3:DiscoveryRequest 
      ns3:DiscoveryResponse 
      DiscoveryServiceFault 
      ns3:EndpointAccessType 
      ns3:EndpointCollection 
      ns3:EndpointType 
      ErrorDetailCollection 
      ns0:KeyValuePairOfEndpointTypestringztYlk6OT 
      ns0:KeyValuePairOfstringanyType 
      ns3:OrganizationDetail 
      ns3:OrganizationDetailCollection 
      ns3:OrganizationRelease 
      OrganizationServiceFault 
      ns3:OrganizationState 
      ns3:RetrieveOrganizationRequest 
      ns3:RetrieveOrganizationResponse 
      ns3:RetrieveOrganizationsRequest 
      ns3:RetrieveOrganizationsResponse 
      ns3:RetrieveUserIdByExternalIdRequest 
      ns3:RetrieveUserIdByExternalIdResponse 
      ns1:char 
      ns1:duration 
      ns1:guid 

e l'errore che ottengo:

DEBUG:suds.transport.http:sending: 
URL:http://crm-test.kavatelecom.net:5555/XRMServices/2011/Discovery.svc 
HEADERS: {'SOAPAction': u'"http://schemas.microsoft.com/xrm/2011/Contracts/Discovery/IDiscoveryService/Execute"', 'Content-Type': 'application/soap+xml', 'Content-type': 'application/soap+xml', 'Soapaction': u'"http://schemas.microsoft.com/xrm/2011/Contracts/Discovery/IDiscoveryService/Execute"'} 
MESSAGE: 
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/xrm/2011/Contracts/Discovery" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><ns0:Body><ns1:Execute><ns1:request xsi:type="ns1:RetrieveOrganizationsRequest"><ns1:AccessType>Default</ns1:AccessType><ns1:Release>Current</ns1:Release></ns1:request></ns1:Execute></ns0:Body></SOAP-ENV:Envelope> 
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/xrm/2011/Contracts/Discovery" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Header/> 
    <ns0:Body> 
     <ns1:Execute> 
     <ns1:request xsi:type="ns1:RetrieveOrganizationsRequest"> 
      <ns1:AccessType>Default</ns1:AccessType> 
      <ns1:Release>Current</ns1:Release> 
     </ns1:request> 
     </ns1:Execute> 
    </ns0:Body> 
</SOAP-ENV:Envelope> 
Traceback (most recent call last): 
    File "newcrm.py", line 32, in <module> 
    resp = client.service.Execute(req) 
    File "/usr/lib/python2.7/site-packages/suds/client.py", line 542, in __call__ 
    return client.invoke(args, kwargs) 
    File "/usr/lib/python2.7/site-packages/suds/client.py", line 602, in invoke 
    result = self.send(soapenv) 
    File "/usr/lib/python2.7/site-packages/suds/client.py", line 649, in send 
    result = self.failed(binding, e) 
    File "/usr/lib/python2.7/site-packages/suds/client.py", line 708, in failed 
    raise Exception((status, reason)) 
Exception: (400, u'Bad Request') 
+0

Hey nim4n, hai ottenuto la risposta a questa domanda, voglio dire che anch'io sto affrontando lo stesso problema Eccezione: (400, u'Bad Request '), e non ho trovato alcuna soluzione. – sandeep

+1

Ho usato il restfull endpoint insted di soap – nim4n

4

Sembra che si è configurato per utilizzare SOAP 1.2. Puoi provare la tua richiesta con Soap 1.1?

Dico questo perché sto guardando questa passeggiata attraverso: http://msdn.microsoft.com/en-us/library/gg594434.aspx

Nella domanda figurava lì è conforme allo standard precedente (come indicato dal tipo MIME.)

Per quanto riguarda come fare questo con la libreria di sud: dopo aver letto un po 'la documentazione, ero propenso a strappare i miei occhi. (Sto solo scherzando, sono abituato a leggere un diverso tipo di documentazione, suppongo.) Sono sicuro che tu sei molto più abituato a sfogliarlo di me, e sarei in grado di capirlo molto velocemente: http://jortel.fedorapeople.org/suds/doc/

+0

tnx per la risposta, controllo il suds doc ma non riesco a trovare nulla per cambiare la versione di soap – nim4n

+2

Sarò onesto, dopo ulteriori ricerche, non è sicuramente banale connettersi a un servizio di organizzazione CRM. Ho provato questo weekend per riprodurre il tuo ambiente, ma il nuovo crm online è la versione 2013, e sono cambiati molto. Una risorsa che potrebbe aiutare è questa: http://code.msdn.microsoft.com/CRM-Online-2011-WebServices-14913a16/sourcecode?fileId=60240&pathId=1778283709 Questo era un progetto in cui l'autore ha impostato una chiamata puramente connettersi al servizio organizzazione. È in C#. Non ho potuto testare perché, ancora una volta, non ho accesso al CRM 2011. –

+0

Penso che inizialmente dovrò connettermi al servizio Discovery e dopo posso utilizzare il servizio di organizzazione. – nim4n