Wednesday, March 23, 2011

What's the best way to specify a proxy with username and password for an **https** connection in python?

I read somewhere that currently urllib2 doesn't support authenticated https connection. My proxy uses a basic authentication only, but how to open an https based webpage through it . Please help me.

Thanks.

From stackoverflow
  • You can use httplib2, which solves some of the limitations of urllib2 including this one. There is an example here of how to do Basic Authentication on a https connection.

  • "urllib2 doesn't support authenticated https connection" False.

        # Build Handler to support HTTP Basic Authentication...
        basic_handler = urllib2.HTTPBasicAuthHandler()
        basic_handler.add_password(realm, self.urlBase, username, password)
        # Get cookies, also, to handle login
        self.cookies= cookielib.CookieJar()
        cookie_handler= urllib2.HTTPCookieProcessor( self.cookies )
        # Assemble the final opener
        opener = urllib2.build_opener(basic_handler,cookie_handler)
    

0 comments:

Post a Comment