2016-10-05 4 views
1

내 목표는 사용자 ID & 암호를 제공하고 세션 개체를 사용하여 POST 요청에서 해당 쿠키를 사용하여 즉시 쿠키를 만드는 것입니다. 그러나 아래 코드는 예외 아래에 반환됩니다.요청 모듈에서 파이썬 오류 "연결 재설정"요청 모듈

() 피어 연결 재설정 '오류 (54'연결이 중단. ')

클래스 CreatePersistentCookie() "" "이 클래스는 또한 통해 사용할 수있는 영구 쿠키를 생성하는 생성 모든 서비스 요청에 대한 세션에서 피어

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 & 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() 

답변

0

연결 재설정은 연결하려는 서버가 연결을 거부 할 수 있음을 나타냅니다 "" "가 실행되는 것을 확인할 수 있습니다. 일반적으로 컴퓨터와 웹 사이트 서버 사이에 핸드 셰이크가 있지만 여기에 어떤 이유로 서버가 연결을 거부하고 있습니다. urllib, 요청, mechanize 및 cookielib 모듈 (일부는 Python 2.7에서만 작동 함)을 사용합니다. 그런 다음 urllib을 사용하면 Firefox와 같은 사용자 - 클라이언트 헤더를 첨부 할 수 있습니다. 그러면 브라우저를 속여서 브라우저를 속이게됩니다. 사용자가 클라이언트가 아니라 웹 서핑을하는 사람이라고 생각하기 때문입니다.