1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with Python code - please

Discussion in 'Programming' started by stuartp, Mar 1, 2015.

  1. #1
    Hi,

    I need some help with some Python code - please.

    What am I doing wrong with the Python code? How can I make the Python code work faster?

    Many thanks for any help.

    ----------------------------------------------------------------

    PYTHON
    
    import time
    from pysimplesoap.client import SoapClient
    
    def checkDomain(vars):
      start = time.clock()
      client = SoapClient(wsdl="https://api.xxxxxxx.com.au/?wsdl")
      data = {'resellerID': vars['resellerID'], 'domainName': vars['domainName'], 'apiKey': vars['apiKey']}
      output=client.checkDomain(data)
      #print "available : %s " % output['return']['available']
      print "status : %s " % output['return']['status']
      end = time.clock()
      print "time : %f " % (end - start)
    
    vars = {
      'resellerID': 'xxxxxxx',
      'domainName': 'xxxxxxx.com',
      'apiKey': 'xxxxxxx'
    }
    
    checkDomain(vars)
    
    Code (markup):
    PYTHON RESSULT
    status : AVAILABLE
    time : 9.981930
    Process finished with exit code 0

    Python results time is usually from 4.5 - 10 seconds

    ----------------------------------------------------------------

    PHP
    
    <?php
    $start = microtime(TRUE);
    echo domainAvailable($domainName="xxxxxxx.com")."<br />\n";
    $finish = microtime(TRUE);
    echo "time : ".($finish - $start);
    
    function domainAvailable($domainName){
       $api_id = 'xxxxxxx';
       $api_key = 'xxxxxxx';
       try {
         // New soap connection
         $client = new SoapClient(null, array('location' => 'https://api.xxxxxxx.com.au/?wsdl','uri' => ""));
         // Data array
         $data = array('resellerID' => $api_id, 'apiKey' => $api_key, 'domainName' => $domainName);   
         // Attempt the update with the API
         $output = $client->checkDomain($data);
         $output->status=trim($output->status);
         if ($output->status == "AVAILABLE") {
           return $output->status;
         }elseif($output->status == "UNAVAILABLE") {
           return $output->status;
         }else{
           return 'Domain Status is unknown: ' . $output->status;     }
       } catch (SoapFault $fault) {
         print_r($fault);
       }
    }
    ?>
    
    Code (markup):
    PHP RESULT
    AVAILABLE
    time : 1.0080101490021

    PHP results time is usually from 1.0 - 2.5 seconds


    Many thanks for your time/ideas - cheers






     
    stuartp, Mar 1, 2015 IP
  2. PDD

    PDD Greenhorn

    Messages:
    67
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    23
    #2
    Are you running this code on an apache server by chance?
     
    PDD, Mar 1, 2015 IP
  3. stuartp

    stuartp Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Hi - thanks for your time.

    It is the latest/fresh install of Python 2 running on a Win 7 machine - many thanks
     
    stuartp, Mar 1, 2015 IP
  4. PDD

    PDD Greenhorn

    Messages:
    67
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    23
    #4
    Try adding this:
    import logging
    
    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('pysimplesoap.client').setLevel(logging.DEBUG)
    Code (python):
    And add trace=True parameter to the soapclient constructor

    need to see what's going on
     
    PDD, Mar 1, 2015 IP
  5. stuartp

    stuartp Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Thanks for your help. I have uploaded the log file - cheers.
     

    Attached Files:

    stuartp, Mar 1, 2015 IP
  6. PDD

    PDD Greenhorn

    Messages:
    67
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    23
    #6
    It's hard to see the bottleneck in big wsdls. I would try it out with SUDs instead. I don't think it's a problem with your code but with the SOAP client and the fact that php is faster than python by default. Check this post for some optimizations if you can apply them: http://stackoverflow.com/questions/7739613/python-soap-client-use-suds-or-something-else/7852994#7852994
     
    PDD, Mar 1, 2015 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    If I may ask - why is it important to get it running faster in Python? It's already working in PHP, why not just use that?
     
    PoPSiCLe, Mar 1, 2015 IP
  8. stuartp

    stuartp Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    Thanks so much PDD - I will check it out - thanks for all your help.

    @PoPSiCLe thanks - I was hoping to use multithreading and PHP can't do multithreading - so I thought I would move it over to Python - cheers
     
    stuartp, Mar 1, 2015 IP