title: Python error "Connection reset by peer" in requests module
body: <p>My goal is to create a persistent cookie on-the-fly by supplying user id &amp; password and use that cookie in POST request using a session object. But below code returns below exception.</p>
  
  <p>('Connection aborted.', error(54, 'Connection reset by peer'))</p>
  
  <p>class CreatePersistentCookie(): """This class is created to generate a persistent cookie that can further be used through out session for all the service requests being executed"""</p>
  
  <pre><code>class CreatePersistentCookie():
      """This class is created to generate a persistent cookie that can further be
         used through out session for all the service requests being executed"""
  
      def __init__(self, headers, data, url, params, authserver):
          self.headers = headers
          self.data = data
          self.url = url
          self.params = params
          self.authserver = authserver
  
      def generateCookie(self):
          with requests.session() as s:
              reqsessionObj = s.post(self.authserver,params = self.params)
              reqCookie = reqsessionObj.request.headers['Cookie'] # this returns the Cookie i need
              regexObj = re.compile(r'act-uat=\S+') # this is my app specific pattern search that returns the exact cookie text i need.
              matchObj = regexObj.search(reqCookie)
              sessionCookie = matchObj.group()
              self.headers['Cookie'] = sessionCookie # adding Cookie attribute in headers.
              try:
                  r = s.post(self.url, data=json.dumps(self.data), headers=self.headers)
                  return r.raise_for_status()
              except requests.exceptions.RequestException as err:
                  print err
  
  def main():
  
      # Defining the params variable. This contains authentication details such as user id,password &amp; App id.
      params = {"accountId": "John",
               "accountPassword": "password",
               "appIdKey": "5c9773e36fd6ea7cc2f9f8ffd9da3e3"
              }
      # Defining the authserver variable that contains the host details where authentication happens.
      authserver = 'https://auth-uat.com/authenticate'
  
      # creating a object cookieObj from class CreatePersistentCookie that returns persistent cookie.
      #print cookies
      headers = {'Content-Type': 'application/json;charset=UTF-8',
                  'Host':'service-uat1.com'}
  
      data = {"appName":"abc","appKey":"abc","type":"jdbc","queryName":"xyz","version":"v1.2","useCache":"false","bindVars":[{"bindVarName":"In_dt","bindVarVal":"2014-05-13"},{"bindVarName":"In_Location","bindVarVal":"USA"}]}
      url = 'https://uat1.com/gsf/abc/derf/abc/services/xyz'
  
      cookieObj = CreatePersistentCookie(headers, data, url, params, authserver)
  
      cookieObj.generateCookie()
  
  if __name__ == '__main__':
      main()
  </code></pre>