title: Consuming Chamilo PHP web services with python
body: <p>Good afternoon,</p>
  <p>I am starting with Python, and I am trying to create a script that will get me a Chamilo user through the webservices that are in PHP.</p>
  <p>In php I do them through NuSoap without problems, but I don't know how to do it in Python.</p>
  <p>PHP example:</p>
  <pre><code>$client = new nusoap_client($url . 'registration.soap.php?wsdl', true);
  $client-&gt;xml_encoding = 'UTF-8';
  $client-&gt;http_encoding = 'UTF-8';
  $client-&gt;charencoding = 'UTF-8';
  
  $client-&gt;soap_defencoding = 'UTF-8';
  
  $soap_error = $client-&gt;getError();
  
  if (!empty($soap_error)) {
      $error_message = 'Nusoap object creation failed: '.$soap_error;
      throw new Exception($error_message);
  }
  $client-&gt;setDebugLevel(10000);
  $client-&gt;debug_flag = true;
  
  $key = 'xxxxxxxxxxxxxxxxxxxxxxx';
          
  $finalKey = sha1($myIp.$key) ;
  
  $params = [
      'username' =&gt; (string) $email ,
      'secret_key' =&gt; $finalKey,
  ];
  
  $result = $client-&gt;call('WSGetUserFromUsername', ['GetUserFromUsername' =&gt; $params]);
  if(!empty($result['user_id'])){
      ...
  }
  </code></pre>
  <p>In pyhon I don't know how to do it.</p>
  <pre><code>import hashlib
  from requests import get, post
  
  url = 'http://xxxxxxxxxx.com/main/webservices/';
  
  # set the WSDL URL
  wsdl_url = url + 'registration.soap.php?wsdl'
  
  security_key = 'xxxxxxxxxxxxxxxx'
  
  my_ip = get(url + 'testip.php').text
  
  secret_key = hashlib.sha1((my_ip + security_key).encode(encoding='UTF-8', errors='strict')).hexdigest()
  
  # Payload
  payload = {
      'username': mail,  # the system field in the user profile (See Profiling)
      'secret_key': secret_key,
  }
  
  headers = {
      'Content-Type': 'text/xml; charset=utf-8',
      'SOAPAction': url + 'registration.soap.php?wsdl'
  }
  
  # Create the SOAP request
  soap_request = ????
  
  # Send the SOAP request
  response = post(wsdl_url, data=soap_request, headers=headers)
  
  # Parse the SOAP response
  soap_response = response.content.decode('utf-8')
  print(soap_response)
  
  </code></pre>
  <p>I don't know if this is how I should do it.
  How can I make the soap request?</p>
  <p>Thank You.</p>