hyper icon indicating copy to clipboard operation
hyper copied to clipboard

HTTP20Adapter object has no attribute 'poolmanager'

Open allanlei opened this issue 8 years ago • 1 comments

Using HTTP20Adapter with requests and closing the session (with context manager) results in attribute error.

Usage:

with requests.Session() as session:
        session.mount(current_app.config['APNS_SERVER'], hyper.contrib.HTTP20Adapter())
        response = session.post(...)
        response.raise_for_status()

Error:

    118                 print(response.request.headers)
    119             else:
--> 120                 print(response.headers[b'apns-id'])
    121 
    122         # try:

blaze/.venv/lib/python3.5/site-packages/requests/sessions.py in __exit__(self, *args)
    367 
    368     def __exit__(self, *args):
--> 369         self.close()
    370 
    371     def prepare_request(self, request):

blaze/.venv/lib/python3.5/site-packages/requests/sessions.py in close(self)
    688         """Closes all adapters and as such the session"""
    689         for v in self.adapters.values():
--> 690             v.close()
    691 
    692     def mount(self, prefix, adapter):

blaze/.venv/lib/python3.5/site-packages/requests/adapters.py in close(self)
    304         which closes any pooled connections.
    305         """
--> 306         self.poolmanager.clear()
    307         for proxy in self.proxy_manager.values():
    308             proxy.clear()

AttributeError: 'HTTP20Adapter' object has no attribute 'poolmanager'

Packages:

h2 (2.6.0.dev0)
hpack (2.3.0)
hyper (0.7.0)
hyperframe (3.2.0)
requests (2.12.1)

allanlei avatar Feb 09 '17 08:02 allanlei

Thanks for raising this! This is a bug caused by the fact that I didn't override the close method of the HTTPAdapter. It would be fixed by overriding HTTP20Adapter.close with the appropriate functionality (in this case, iterating the connections and closing them all).

This is not a high urgency issue for me right now (I'm working on a few big bits of functionality that aren't easily interrupted for this), so while I may get to it eventually if someone wants to come along and make a pull request that will address this I'll happily review and merge.

Lukasa avatar Feb 09 '17 09:02 Lukasa