Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8120041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:59:46+00:00 2026-06-06T04:59:46+00:00

I’m trying to make a https get request from behind a squid proxy with

  • 0

I’m trying to make a https get request from behind a squid proxy with cac card authentication. Loading the opensc engine and grabbing the cert and private key seem to work fine. Below is the traceback and the code.

Any help is greatly appreciated.

Traceback

Traceback (most recent call last):
File "testM2Crypto.py", line 64, in <module>
res = m2urllib2.urlopen(req)
File "c:\Python27\lib\urllib2.py", line 135, in urlopen
return _opener.open(url, data, timeout)
File "c:\Python27\lib\urllib2.py", line 415, in open
response = self._open(req, data)
File "c:\Python27\lib\urllib2.py", line 433, in _open
'_open', req)
File "c:\Python27\lib\urllib2.py", line 387, in _call_chain
result = func(*args)
File "c:\Python27\lib\site-packages\M2Crypto\m2urllib2.py", line 94, in https_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "c:\Python27\lib\httplib.py", line 963, in request
self._send_request(method, url, body, headers)
File "c:\Python27\lib\httplib.py", line 994, in _send_request
self.putrequest(method, url, **skips)
File "c:\Python27\lib\site-packages\M2Crypto\httpslib.py", line 140, in putrequest
raise ValueError, "unknown URL type: %s" % url
ValueError: unknown URL type: /index.asp?site=SomeSite

Code

from M2Crypto import httpslib, m2urllib2, m2, SSL, Engine
import urllib2

url = 'https://some.domain.com/index.asp?site=SomeSite'

e = Engine.load_dynamic_engine("pkcs11", "c:/windows/syswow64/engine_pkcs11.dll")
pk = Engine.Engine("pkcs11")
pk.ctrl_cmd_string("MODULE_PATH", "c:/windows/syswow64/opensc-pkcs11.dll")
m2.engine_init(m2.engine_by_id("pkcs11"))

cert = e.load_certificate("slot_01-id_01")
privatekey = e.load_private_key("slot_01-id_01")

ctx = SSL.Context("sslv23")
ctx.set_cipher_list("HIGH:!aNULL:!eNULL:@STRENGTH")
ctx.set_session_id_ctx("foobar")
m2.ssl_ctx_use_x509(ctx.ctx, cert.x509)
m2.ssl_ctx_use_pkey_privkey(ctx.ctx, privatekey.pkey)

proxy_support=urllib2.ProxyHandler({'https':'https://proxy:3128'})
opener = m2urllib2.build_opener(ctx, proxy_support)
m2urllib2.install_opener(opener)
req = m2urllib2.Request(url)
res = m2urllib2.urlopen(req)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:59:47+00:00Added an answer on June 6, 2026 at 4:59 am

    I finally was able to solve the problem yesterday. I had to make a few modifications to the code. I also had to patch a bug in the M2Crypto library that was preventing https through a proxy(Thanks to Miloslav Trmač from redhat for the patch). The solution is below for anyone else who might be running into a similar problem. Hope this helps.

    Code

    from M2Crypto import httpslib, m2urllib2, m2, SSL, Engine
    import urllib2
    
    userPin = "123456"
    rootCertPath = 'd:/path/to/rootCert.pem'
    url = 'https://some.domain.com/index.asp?site=SomeSite'
    
    e = Engine.load_dynamic_engine("pkcs11", "c:/windows/syswow64/engine_pkcs11.dll")
    pk = Engine.Engine("pkcs11")
    pk.ctrl_cmd_string("MODULE_PATH", "c:/windows/syswow64/opensc-pkcs11.dll")
    if len(userPin) > 0: pk.ctrl_cmd_string("PIN", userPin)
    
    m2.engine_init(m2.engine_by_id("pkcs11"))
    
    rootcert = X509.load_cert(rootCertPath)
    cert = e.load_certificate("slot_01-id_01")
    privatekey = e.load_private_key("slot_01-id_01")
    
    ctx = SSL.Context("sslv23")
    ctx.set_cipher_list("HIGH:!aNULL:!eNULL:@STRENGTH")
    ctx.set_session_id_ctx("foobar")
    ctx.load_verify_locations(cafile=rootcert)
    m2.ssl_ctx_use_x509(ctx.ctx, cert.x509)
    m2.ssl_ctx_use_pkey_privkey(ctx.ctx, privatekey.pkey)
    
    proxy_support=urllib2.ProxyHandler({'https':'https://proxy:3128'})
    opener = m2urllib2.build_opener(ctx, proxy_support)
    m2urllib2.install_opener(opener)
    req = m2urllib2.Request(url)
    try:
        res = m2urllib2.urlopen(req)
        print '\nsuccess'
    except urllib2.HTTPError, err:
        print '\nerror'
        print 'err.code: '+str(err.code)
        print 'err.reason: '+str(err.reason)
        print 'err.read(): '+str(err.read())
    

    Thanks to Miloslav Trmač from redhat for the patch. I found this patch at the following url, http://arm.koji.fedoraproject.org/koji/buildinfo?buildID=61225 .

    M2Crypto Patch

    diff -urN M2Crypto/M2Crypto/httpslib.py M2Crypto-0.21.1/M2Crypto/httpslib.py
    --- M2Crypto/M2Crypto/httpslib.py   2012-03-15 03:27:22.181524406 +0100
    +++ M2Crypto-0.21.1/M2Crypto/httpslib.py    2012-03-15 03:27:40.467485033 +0100
    @@ -182,14 +182,14 @@
             else:
                 HTTPSConnection.putheader(self, header, value)
    
    -    def endheaders(self):
    +    def endheaders(self, *args, **kwargs):
             # We've recieved all of hte headers. Use the supplied username
             # and password for authorization, possibly overriding the authstring
             # supplied in the headers.
             if not self._proxy_auth:
                 self._proxy_auth = self._encode_auth()
    
    -        HTTPSConnection.endheaders(self)
    +        HTTPSConnection.endheaders(self, *args, **kwargs)
    
         def connect(self):
             HTTPConnection.connect(self)
    diff -urN M2Crypto/M2Crypto/m2urllib2.py M2Crypto-0.21.1/M2Crypto/m2urllib2.py
    --- M2Crypto/M2Crypto/m2urllib2.py  2011-01-15 20:10:05.000000000 +0100
    +++ M2Crypto-0.21.1/M2Crypto/m2urllib2.py   2012-03-15 03:27:40.467485033 +0100
    @@ -64,8 +64,10 @@
             target_host = urlparse.urlparse(full_url)[1]
    
             if (target_host != host):
    +            request_uri = urlparse.urldefrag(full_url)[0]
                 h = httpslib.ProxyHTTPSConnection(host = host, ssl_context = self.ctx)
             else:
    +            request_uri = req.get_selector()
                 h = httpslib.HTTPSConnection(host = host, ssl_context = self.ctx)
             # End our change
             h.set_debuglevel(self._debuglevel)
    @@ -80,7 +82,7 @@
             # request.
             headers["Connection"] = "close"
             try:
    -            h.request(req.get_method(), req.get_selector(), req.data, headers)
    +            h.request(req.get_method(), request_uri, req.data, headers)
                 r = h.getresponse()
             except socket.error, err: # XXX what error?
                 raise URLError(err)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.