Search code examples
pythonsslhttpsntlmpycurl

Pycurl ssl connection throught ntlm


I am struggling with connection to https sites and files. We have ntlm network proxy authentication. HTTP connections are working like a charm, but https is stuck with error:

pycurl.error: (27, "SSL: couldn't create a context: error:140A90A1:lib(20):func(169):reason(161)")

I tried verifypeer to 0, but it doesnt work, the same with: conn.setopt(pycurl.SSL_CIPHER_LIST, 'rsa_rc4_128_sha'). I want to download: https://nbp.pl/kursy/xml/LastA.xml. Any clue?

The code:

conn=pycurl.Curl()
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.PROXY, proxy)
conn.setopt(pycurl.PROXYPORT,8080)
conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_NTLM)
conn.setopt(pycurl.PROXYUSERPWD, user)
conn.setopt(pycurl.WRITEFUNCTION, open(r'xml\\'+name+'.'+extension,'w+').write)
conn.perform()
conn.close()

Solution

  • Got success with a bypass using CNTLM.

    The code:

    proxy = urllib2.ProxyHandler({'https':'127.0.0.1:3128'})
    opener = urllib2.build_opener(proxy)
    urllib2.install_opener(opener)
    u = urllib2.urlopen(url)
    data = u.read()
    fil=open(r'xml\\'+name+'.'+extension,'w+')
    fil.write(data)