Показать сообщение отдельно

  #3  
Старый 18.05.2009, 11:07
Gifts
Reservists Of Antichat - Level 6
Регистрация: 25.04.2008
Сообщений: 827
С нами: 9497186

Репутация: 1304


По умолчанию

Помогите, cookielib почему-то не принимает все куки.

Есть такой код
Код:
    def request(self, host, handler, request_body, verbose=0):
        # dummy request class for extracting cookies 
        class CookieRequest(urllib2.Request):
            pass            

        # dummy response class for extracting cookies 
        class CookieResponse:
            def __init__(self, headers):
                self.headers = headers
            def info(self):
                return self.headers 
        verbose = 0
        crequest = CookieRequest('https://'+host+'/')
            
        # issue XML-RPC request
        h = self.make_connection(host)
        if verbose:
            h.set_debuglevel(1)

        self.send_request(h, handler, request_body)
        self.send_host(h, host)
        self.send_user_agent(h)
        
        # creating a cookie jar for my cookies
        cj = cookielib.LWPCookieJar()

        self.send_content(h, request_body)

        errcode, errmsg, headers = h.getreply()
        print str(headers)
        cresponse = CookieResponse(headers)
        cj.extract_cookies(cresponse, crequest)

        if len(cj) >0 and self.cookiefile != None:
            cj.save(self.cookiefile)
                
        if errcode != 200:
            raise xmlrpclib.ProtocolError(
                host + handler,
                errcode, errmsg,
                headers
                )

        self.verbose = verbose

        try:
            sock = h._conn.sock
        except AttributeError:
            sock = None
                
        return self._parse_response(h.getfile(), sock)
Приходящие заголовки выглядят так:
Код:
Server: nginx/0.6.32
Date: Mon, 18 May 2009 06:59:05 GMT
Content-Type: text/xml; charset=utf-8
Connection: close
Set-Cookie: SAPE=tra-ta-ta; path=/; domain=.sape.ru
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: p=a8de899da4; expires=Tue, 18-May-2010 06:59:02 GMT; path=/; domain=.sape.ru
Суть - сохраняет только куку "p", но не "SAPE" возможно из-за отсутствия аттрибута expires. Как настроить, чтобы сохранялись все куки?
 
Ответить с цитированием