AttributeError: 'HTTPAdapter' object has no attribute 'proxy_manager'

I'm running requests version 2.0.1 on OSX 10.9 and proxying through Charles Proxy.

I've been getting the following traceback when trying query an API.  Looks like the `proxy_manager` is not getting set in the object.

``` python

        # requests session is setup like this:
        headers = {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71',
            'Content-type': 'application/json',
                }
        proxies = {
            "http": "http://127.0.0.1:8888",
            "https": "http://127.0.0.1:8888",
        }
        s = requests.session()
        s.headers.update(headers)
        s.proxies = proxies
        s.get(url) # pseudo code



  File "/Users/erik/.virtualenvs/proj/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2827, in run_code
    exec code_obj in self.user_global_ns, self.user_ns
  File "<ipython-input-6-db63d61cf602>", line 1, in <module>
    tasks.process_transparency_report(r.pk)
  File "/Users/erik/.virtualenvs/proj/lib/python2.7/site-packages/celery/local.py", line 165, in <lambda>
    __call__ = lambda x, *a, **kw: x._get_current_object()(*a, **kw)
  File "/Users/erik/.virtualenvs/proj/lib/python2.7/site-packages/celery/app/task.py", line 409, in __call__
    return self.run(*args, **kwargs)
  File "/Users/erik/Dropbox/home/git/proj/anx/tasks.py", line 417, in process_transparency_report
    resp = report_job.check_report_job_status()
  File "/Users/erik/Dropbox/home/git/proj/portal/models.py", line 4437, in check_report_job_status
    resp = anx.report_service.report_job_status(self.report_id)
  File "/Users/erik/Dropbox/home/git/proj/anx/api.py", line 784, in report_job_status
    resp = self.get(url, params=params)
  File "/Users/erik/Dropbox/home/git/proj/anx/api.py", line 124, in get
    resp = self.browser.get(url, params=params, **kwargs)
  File "/Users/erik/.virtualenvs/proj/lib/python2.7/site-packages/requests/sessions.py", line 373, in get
    return self.request('GET', url, **kwargs)
  File "/Users/erik/.virtualenvs/proj/lib/python2.7/site-packages/requests/sessions.py", line 361, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/erik/.virtualenvs/proj/lib/python2.7/site-packages/requests/sessions.py", line 464, in send
    r = adapter.send(request, **kwargs)
  File "/Users/erik/.virtualenvs/proj/lib/python2.7/site-packages/requests/adapters.py", line 296, in send
    conn = self.get_connection(request.url, proxies)
  File "/Users/erik/.virtualenvs/proj/lib/python2.7/site-packages/requests/adapters.py", line 202, in get_connection
    if not proxy in self.proxy_manager:
  AttributeError: 'HTTPAdapter' object has no attribute 'proxy_manager'
```


You're going to have to use some real code, I'm afraid, because that simply shouldn't be possible. Initialising the `HTTPAdapter` object also initialises `proxy_manager` to an empty dictionary, so it should be impossible for that `AttributeError` to be raised.


@erikcw Any updates on this issue? I'm really curious about how that happens in normal use case.


I haven't had time to factor the code out into a small reproducible sample yet.  From my testing, it seems to either be an issue with Charles Proxy (strange since everything else seems work work well with it), or OSX.  I don't have this issue when I run the code on our production servers (Linux).  

Also, as an additional data point, I'm using a pickled copy of the the session object (to preserve session cookies for the API I'm consuming).

Creating a new session seems to help in avoiding the exception.


Heh, well mentioning that you're pickling looks like the obvious problem to me. I think `HTTPAdapter.__setstate__()` should probably be setting `HTTPAdapter.proxy_manager` to the empty dictionary. =D


That did the trick!

I put together a quick pull request with the fix.  This commit also fixes one of the failing unit tests in the existing suite... (`test_session_pickling`)


@erikcw There already is related PR :)
https://github.com/kennethreitz/requests/pull/1793


Fixed by #1793 (ages ago). =3