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 643801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:19:20+00:00 2026-05-13T21:19:20+00:00

I’m using httplib2 to make a request from my server to another web service.

  • 0

I’m using httplib2 to make a request from my server to another web service. We want to use mutual certificate authentication. I see how to use a certificate for the outgoing connection (h.set_certificate), but how do I check the certificate used by the answering server?

This ticket seems to indicate that httplib2 doesn’t do it itself, and has only vague suggestions about where to look.

Is it possible? Am I going to have to hack at a lower level?

  • 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-05-13T21:19:21+00:00Added an answer on May 13, 2026 at 9:19 pm

    Here’s the code my co-worker Dave St. Germain wrote to solve the problem:

    import ssl
    import socket
    from httplib2 import has_timeout
    import httplib2
    import socks
    
    
    class CertificateValidationError(httplib2.HttpLib2Error):
        pass
    
    
    def validating_sever_factory(ca_cert_file):
        # we need to define a closure here because we don't control
        # the arguments this class is instantiated with
        class ValidatingHTTPSConnection(httplib2.HTTPSConnectionWithTimeout):
    
            def connect(self):
                # begin copypasta from HTTPSConnectionWithTimeout
                "Connect to a host on a given (SSL) port."
    
                if self.proxy_info and self.proxy_info.isgood():
                    sock = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
                    sock.setproxy(*self.proxy_info.astuple())
                else:
                    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
                if has_timeout(self.timeout):
                    sock.settimeout(self.timeout)
                sock.connect((self.host, self.port))
                # end copypasta
    
    
                try:
                    self.sock = ssl.wrap_socket(sock,
                                self.key_file,
                                self.cert_file,
                                cert_reqs=ssl.CERT_REQUIRED,
                                ca_certs=ca_cert_file
                                )
                except ssl.SSLError:
                    # we have to capture the exception here and raise later because 
                    # httplib2 tries to ignore exceptions on connect
                    import sys
                    self._exc_info = sys.exc_info()
                    raise
                else:
                    self._exc_info = None
    
                    # this might be redundant
                    server_cert = self.sock.getpeercert()
                    if not server_cert:
                        raise CertificateValidationError(repr(server_cert))
    
            def getresponse(self):
                if not self._exc_info:
                    return httplib2.HTTPSConnectionWithTimeout.getresponse(self)
                else:
                    raise self._exc_info[1], None, self._exc_info[2]
        return ValidatingHTTPSConnection
    
    
    def do_request(url,
            method='GET',
            body=None,
            headers=None,
            keyfile=None,
            certfile=None,
            ca_certs=None,
            proxy_info=None,
            timeout=30):
        """
        makes an http/https request, with optional client certificate and server
        certificate verification.
        returns response, content
        """
        kwargs = {}
        h = httplib2.Http(proxy_info=proxy_info, timeout=timeout)
        is_ssl = url.startswith('https')
        if is_ssl and ca_certs:
            kwargs['connection_type'] = validating_sever_factory(ca_certs)
    
        if is_ssl and keyfile and certfile:
            h.add_certificate(keyfile, certfile, '')
        return h.request(url, method=method, body=body, headers=headers, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.