<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'error' in adapters.py

```
  File "/something/lib/python2.7/site-packages/requests/api.py", line 88, in post
  File "/something/lib/python2.7/site-packages/requests/api.py", line 44, in request
  File "/something/lib/python2.7/site-packages/requests/sessions.py", line 335, in request
  File "/something/lib/python2.7/site-packages/requests/sessions.py", line 438, in send
  File "/something/lib/python2.7/site-packages/requests/adapters.py", line 323, in send
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'error'
```

Seems to happen very rare.


That seems like a weird exception. That line is `except socket.error`. Out of interest, do you ever touch `requests.adapters.socket`?


I did not.

If the line says socket.error, then probably somewhere socket name is overriden...


Yeah, that's my concern. It's worth checking in your application.


The thing is, I have not a single `socket` word directly in that cli. And it happens time to time.


So it's always going to be transient, because you'll only hit it when you actually throw an exception. If you want to see what's happening, try replacing the series of `except` blocks around that point with the following:

``` python
except Exception, e:
    print "Current value of socket: %s" % socket
    raise
```

That should raise the original exception (so you can see what you're actually hitting) and also provide the value of `socket` at that time.


@Lukasa  you don't have to explain to me such obvious things, really ;-)

The problem is that it happens very rare, when it happened it was Connection Reset probably. Also it happened from daemonized thread (daemon=True). The real problem is that it happened once a milion reqs or so. I wonder if it's not a GC "problem" in python or something.


Heh, sorry. ;) I've found it better to just be excessively helpful all the time, even when it means saying something fairly obvious. =D

Could be a GC problem but it's hard to imagine how that's invalidating the socket module we're holding on to. That statement is just totally benign. I'm not entirely sure what your next good step would be.


np ;-)

> I'm not entirely sure what your next good step would be.

So do I, that's why I created the issue right now.


Garbage collection does not collect modules or module bindings to names to the best of my knowledge. I think reading [this section of the `threading` docs](http://docs.python.org/2/library/threading.html#importing-in-threaded-code) may be worth reading. I have to wonder when socket is being imported (before or after the thread is created and main execution has finished). I would normally expect a `NameError` but if importing causes `socket` to be bound to `None` then that may explain your issue. In other words, I'm tempted to believe this is not a bug in requests but rather a timing issue in your code.

Edit requests/adapters to place `print('This is the value of socket: %s' % socket)` immediately after `import socket`. This will probably provide a clue.


Closing due to inactivity.


This issue started happening to me when shutting down a Docker container running Tornado. 

```
Gracefully stopping... (press Ctrl+C again to force)
Stopping rethinktags_rethinkdb_1...
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/code/build/docker-compose/out00-PYZ.pyz/threading", line 552, in __bootstrap_inner
  File "/code/build/docker-compose/out00-PYZ.pyz/threading", line 505, in run
  File "/code/build/docker-compose/out00-PYZ.pyz/compose.cli.multiplexer", line 41, in _enqueue_output
  File "/code/build/docker-compose/out00-PYZ.pyz/compose.cli.log_printer", line 62, in _make_log_generator
  File "/code/build/docker-compose/out00-PYZ.pyz/compose.container", line 140, in wait
  File "/code/build/docker-compose/out00-PYZ.pyz/docker.client", line 918, in wait
  File "/code/build/docker-compose/out00-PYZ.pyz/docker.client", line 79, in _post
  File "/code/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 425, in post
  File "/code/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 383, in request
  File "/code/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 486, in send
  File "/code/build/docker-compose/out00-PYZ.pyz/requests.adapters", line 374, in send
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'error'
```


@dalanmiller Can you follow @sigmavirus24's advice from earlier in the thread, please?