python pycurl giving for soap error of gnutls
Question: While trying pycurl for some url

    
    
     def call_soap_curl(ncServerURL, xml, action):
    
      c = pycurl.Curl()
      c.setopt(pycurl.URL, ncServerURL)
      c.setopt(pycurl.POST, 1)
      c.setopt(pycurl.SSL_VERIFYPEER, 0)
      c.setopt(pycurl.SSL_VERIFYHOST, 0)
      header=["Content-type: text/xml","SOAPAction:"+action,'Content-Type: text/xml; charset=utf-8','Content-Length: '+str(len(xml))]
      print header
      c.setopt(pycurl.HTTPHEADER, header)
      c.setopt(pycurl.POSTFIELDS, str(xml))
      import StringIO
      b = StringIO.StringIO()
      c.setopt(pycurl.WRITEFUNCTION, b.write)
      c.perform()
      ncServerData = b.getvalue()
      return ncServerData
    

The error m getting is

    
    
    (56, 'GnuTLS recv error (-9): A TLS packet with unexpected length was received.')
      @c.perform()
    

Please suggest what can be problem , how can i solve this. **Using Ubuntu and
same url in curl in php working**

This is my

    
    
     pycurl.version_info()
    (3, '7.21.6', 464134, 'x86_64-pc-linux-gnu', 17981, 'GnuTLS/2.10.5', 0, '1.2.3.4', ('dict', 'file', 'ftp', 'ftps', 'gopher', 'http', 'https', 'imap', 'imaps', 'ldap', 'pop3', 'pop3s', 'rtmp', 'rtsp', 'smtp', 'smtps', 'telnet', 'tftp'), None, 0, '1.22')
    


Answer: This seems to be a problem with libcurl compiled with GnuTLS.

Elsewhere I read:

_<https://bugs.launchpad.net/gwibber/+bug/626023/comments/28> was also
suggested, "The only way i managed to get rid of that error, was by
recompiling libcurl with OpenSSL instead of GnuTLS and then recompiling
python-pycurl against the new cURL library_

I recompiled libcurl with OpenSSL as suggested and the problem was solved for
me. I've included my recipe here for inspiration, though it's Ubuntu specific.

    
    
    #!/bin/bash
    
    sudo apt-get install libcurl4-openssl-dev
    
    wget http://curl.haxx.se/download/curl-7.26.0.tar.gz
    wget http://pycurl.sourceforge.net/download/pycurl-7.19.0.tar.gz
    tar -xzvf pycurl-7.19.0.tar.gz
    tar -xzvf curl-7.26.0.tar.gz
    cd curl-7.26.0/
    ./configure --with-ssl
    make
    sudo make install
    cd ../pycurl-7.19.0/
    sudo python setup.py install
    
    sudo ldconfig
    

