jirumiro / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

Wrong instruction about parameter connection_type of request method at documentation #291

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
At documentation it says

The connection_type is the type of connection object to use. The supplied class 
should implement the interface of httplib.HTTPConnection.

In

Http.request(uri[, method="GET", body=None, headers=None, 
redirections=DEFAULT_MAX_REDIRECTS, connection_type=None])

At
http://httplib2.googlecode.com/hg/doc/html/libhttplib2.html#httplib2.Http.reques
t

But this can't be true since in the code I see:

https://code.google.com/p/httplib2/source/browse/python2/httplib2/__init__.py#14
71

 if not connection_type:
                    connection_type = SCHEME_TO_CONNECTION[scheme]
                certs = list(self.certificates.iter(authority))
                if scheme == 'https':
                    if certs:
                        conn = self.connections[conn_key] = connection_type(
                                authority, key_file=certs[0][0],
                                cert_file=certs[0][1], timeout=self.timeout,
                                proxy_info=proxy_info,
                                ca_certs=self.ca_certs,
                                disable_ssl_certificate_validation=
                                        self.disable_ssl_certificate_validation)
                    else:
                        conn = self.connections[conn_key] = connection_type(
                                authority, timeout=self.timeout,
                                proxy_info=proxy_info,
                                ca_certs=self.ca_certs,
                                disable_ssl_certificate_validation=
                                        self.disable_ssl_certificate_validation)
                else:
                    conn = self.connections[conn_key] = connection_type(
                            authority, timeout=self.timeout,
                            proxy_info=proxy_info)
                conn.set_debuglevel(debuglevel)

proxy_info parameter is used to build the connection, but httplib.HTTPConnection
at http://docs.python.org/2/library/httplib.html#httplib.HTTPConnection
don't expect proxy_info parameter in the constructor:

So when doing something like this:

    class HTTPSConnectionV3(httplib.HTTPSConnection):
        def __init__(self, *args, **kwargs):
            httplib.HTTPSConnection.__init__(self, *args, **kwargs)

And then this:

h1 = httplib2.Http()                                                
resp, content = h1.request(testurl, "GET", connection_type=HTTPSConnectionV3)

I get a error like this:

Traceback (most recent call last):
  File "./testhttplib2.py", line 36, in <module>
    resp, content = h1.request("myurl", "GET", connection_type=HTTPSConnectionV3)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 1328, in request
    proxy_info=self.proxy_info)
  File "./testhttplib2.py", line 8, in __init__
    httplib.HTTPSConnection.__init__(self, *args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'proxy_info'

Original issue reported on code.google.com by oniltonm...@gmail.com on 7 Aug 2013 at 5:59

GoogleCodeExporter commented 8 years ago
As a workaround you can do:

    class HTTPSConnectionV3(httplib.HTTPSConnection):
        def __init__(self, *args, **kwargs):
            filtered_kwargs = {k: v for (k,v) in kwargs.iteritems() if k != 'proxy_info'}                                                            
            httplib.HTTPSConnection.__init__(self, *args, **filtered_kwargs)

Original comment by oniltonm...@gmail.com on 7 Aug 2013 at 6:13