If socket is none requests started creating a new connection

Hi,

I am constantly seeing Resetting dropped connection for every URL, 

Could you please let me know Why i am getting and how do i avoid such error message?

Here is python snippet

``` python
def __init__(self, base_url, username, password):
        self.session = requests.Session()
        self.session.auth = (username, password)        
        adapter = requests.adapters.HTTPAdapter(pool_connections=1, pool_maxsize=100, pool_block=True, max_retries=0)
        self.session.mount('http://', adapter)
        self.base_url = base_url
        start_url = base_url + 'index.html'
        _req = self.session.get(start_url)
        self.cookie = _req.cookies        
        print self.cookie

    def get_entry(self, url):
        print self.cookie
        _req = self.session.get(url, cookies=self.cookie)               
        print _req.headers
        return _req

    def post_entry(self, url, body):
        header = {"Content-type":"application/json"}
        print self.cookie
        _req = self.session.post(url=url, data=body, cookies=self.cookie, headers=header)
        print _req.headers
        print _req.text
        return _req
```

Thanks
Malli


I further debugged and I came to the socket information has, If socket is none, requests started creating a new connection

``` Python
def is_connection_dropped(conn):  # Platform-specific
    """
    Returns True if the connection is dropped and should be closed.
    :param conn:
        :class:`httplib.HTTPConnection` object.
    Note: For platforms like AppEngine, this will always return ``False`` to
    let the platform handle connection recycling transparently for us.
    """
    sock = getattr(conn, 'sock', False)
    if sock is False:  # Platform-specific: AppEngine
        return False
    if sock is None:  # Connection already closed (such as by httplib).
        return True
```

However the cookie information is common across all the connection

Is socket information must be False every time?

My HTTP debug information

``` HTTP
<RequestsCookieJar[<Cookie session=4D51754C for 10.11.18.11/>]> 

connection <requests.packages.urllib3.connection.HTTPConnection object at 0x032FD5F0> 
{'_HTTPConnection__state': 'Idle', '_buffer': [], '_create_connection': <function create_connection at 0x02ABF130>, '_tunnel_headers': {}, '_tunnel_host': None, 'sock': None, 'port': 80, 'strict': True, 'host': '10.11.18.11', '_tunnel_port': None, 'timeout': None, 'socket_options': [(6, 1, 1)], 'source_address': None, '_HTTPConnection__response': None, '_method': 'GET'} 

send: 'GET test/one/data HTTP/1.1\r\nHost: 10.11.18.11\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nUser-Agent: python-requests/2.8.1\r\nConnection: keep-alive\r\nCookie: session=4D51754C\r\nAuthorization: Basic QURNSU46UEFTU1dPUkQ=\r\n\r\n' reply: 'HTTP/1.0 200 OK\r\n' header: Server: xxx TinyServer header: MIME-version: 1.0 header: Cache-Control: no-store, no-cache; header: Pragma: no-cache; header: Set-Cookie: session=4D51754C; path=/; header: Content-Type: application/json header: Expires: -1 header: Content-Length: 2 {'Content-Length': '2', 'Set-Cookie': 'session=4D51754C; path=/;', 'Expires': '-1', 'Server': 'ADTRAN TinyServer', 'Pragma': 'no-cache;', 'Cache-Control': 'no-store, no-cache;', 'Content-Type': 'application/json', 'MIME-version': '1.0'}
```

Thanks
Malli


Thanks for this @vkosuri!

This is expected behaviour. Requests attempts to "connection pool", which means that it attempts to reuse sockets as frequently as possible. Sometimes, requests will come to try to re-use a socket and find that the underlying TCP connection got closed while it's away. When that happens, it'll reset the connection. We mention this in the logs because it's potentially important to debug very subtle issues.

The important things to know are:
- this is a log message, not a warning or error message
- it's logged at INFO level, which is fairly low

If you want to make the message go away, simply set the log level higher than INFO or disable logging for the `requests.packages.urllib3` logger.


@Lukasa How to disable Retrying warning messages?

```
[ WARN ] Retrying (Retry(total=9, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7fe2c71ad150>: Failed to establish a new connection: [Errno 111] Connection refused',)'
```

I am getting thousands of Warning messages in my testcase, due to this effect the log file size was increasing drastically. Is there any possibility to remove/disable warning message when NewConnectionError ?


@vkosuri That warning is raised by urllib3. If you want to disable that message, either handle retries yourself (stop passing the parameter into urllib3), or raise the log level for urllib3, or disable logging from urllib3 entirely. The logger you want to disable is the one at `requests.packages.urllib3.connectionpool`.


Thank you @Lukasa I am using [Robotframework-Requests](https://github.com/bulkan/robotframework-requests). I have added fallowing lines code to [Requests.py](https://github.com/bulkan/robotframework-requests/blob/master/src/RequestsLibrary/RequestsKeywords.py)

Still it is not working? Am i missed anything? Could you please suggest me?

``` Python
# Disable warnings
logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
```


That has _enabled_ logging, not disabled it. You need to set the level higher than that (e.g. to logging.ERROR).


Thanks @Lukasa It's working

``` Python
logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests
logging.getLogger().setLevel(logging.ERROR)
requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.ERROR)
requests_log.propagate = True
```