나는 WSGI 응용 프로그램을 unittesting하고 있습니다. 파이썬 3.2로 작성했습니다. 한 요청에서 다음 요청으로 세션 쿠키를 전달할 방법을 찾고있었습니다.단위 테스트 http 세션 쿠키 python3
self.cli는
def testLogonCookie(self):
self.cli.connect()
self.cli.request("POST", '/login', b'user=GUI&pass=Junkie')
res = self.cli.getresponse()
heads = res.getheader('Set-Cookie')
print(heads)
txt = str(res.readall())
self.assertGreater(txt.find('Lorum ipsum'), -1, 'testLogin')
head = {"HTTP_COOKIE": heads}
print(head)
####Exception here
self.cli.request('GET', '/loggedon', head)
res = self.cli.getresponse()
txt = str(res.readall())
print(txt)
self.assertGreater(txt.find('user=GUI_Junkie'), -1, 'testLogonCookie')
첫 번째 인쇄 미량 인 SID = 0422f293-58e4-45a9-ab07- http.client.HTTPConnection 쿠키가 http.cookies.SimpleCookie에게이다
이다a4881c7b98d0; 만료 = 2014-03-29 17 : 39 : 55.868140
둘째 줄은 { 'HTTP_COOKIE': 'SID = 0422f293-58e4-45a9-ab07-a4881c7b98d0; 만료 = 2014년 3월 29일 17 : 39 : 55.868140 '}
내가 얻을 예외 나는 내가 getheader
을 분석하고 딕셔너리에 넣어 가지고 의심하지만,이 있는지 궁금하네요 TypeError: 'str' does not support the buffer interface
입니다 그것에 대해가는 더 쉬운 길. 결국 쿠키를 하나의 요청에서 다른 요청으로 푸시합니다.