xmlrpc, extract data from http headers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Milos Prudek

    #1

    xmlrpc, extract data from http headers

    I perform a XML-RPC call by calling xmlrpclibBasicA uth which in turn calls
    xmlrpclib. This call of course sends a HTTP request with correct HTTP
    headers. The response is correctly parsed by xmlrpclib, and I get my desired
    values.

    However, I also need to get the raw HTTP headers from the HTTP response. There
    is a cookie in the HTTP response and I need to read that cookie.

    How could I do that?

    --
    Milos Prudek
  • Filip Wasilewski

    #2
    Re: xmlrpc, extract data from http headers

    Milos Prudek wrote:
    I perform a XML-RPC call by calling xmlrpclibBasicA uth which in turn calls
    xmlrpclib. This call of course sends a HTTP request with correct HTTP
    headers. The response is correctly parsed by xmlrpclib, and I get my desired
    values.
    >
    However, I also need to get the raw HTTP headers from the HTTP response. There
    is a cookie in the HTTP response and I need to read that cookie.
    >
    How could I do that?
    Overload the _parse_response method of Transport in your
    BasicAuthTransp ort and extract headers from raw response. See the
    source of xmlrpclib.py in the standard library for details.

    cheers,
    fw

    Comment

    • Milos Prudek

      #3
      Re: xmlrpc, extract data from http headers

      Overload the _parse_response method of Transport in your
      BasicAuthTransp ort and extract headers from raw response. See the
      source of xmlrpclib.py in the standard library for details.
      Thank you.

      I am a bit of a false beginner in Python. I have written only short scripts. I
      want to read "Dive into Python" to improve my knowledge. Your advice is
      perfect. It is my fault that I need a little more guidance.

      I am not sure how the headers will be passed from Transport to the instance of
      ServerProxy. That is, if I change the _parse_response method, how do I
      retreive the headers using the ServerProxy command?


      --
      Milos Prudek

      Comment

      • Filip Wasilewski

        #4
        Re: xmlrpc, extract data from http headers

        Milos Prudek wrote:
        Overload the _parse_response method of Transport in your
        BasicAuthTransp ort and extract headers from raw response. See the
        source of xmlrpclib.py in the standard library for details.
        >
        Thank you.
        >
        I am a bit of a false beginner in Python. I have written only short scripts. I
        want to read "Dive into Python" to improve my knowledge. Your advice is
        perfect. It is my fault that I need a little more guidance.
        >
        I am not sure how the headers will be passed from Transport to the instance of
        ServerProxy. That is, if I change the _parse_response method, how do I
        retreive the headers using the ServerProxy command?
        Erm, now I see that my previous response was incorrect, sorry. The
        headers are not passed to the _parse_response method.

        A better solution would be to extract cookies from headers in the
        request method and return them with response (see the code below). I
        still wonder if there is an easy way to use CookieJar from cookielib
        with xmlrpclib.

        class CookieTransport (xmlrpclib.Tran sport):
        def request(self, host, handler, request_body, verbose=0):
        h = self.make_conne ction(host)
        if verbose:
        h.set_debugleve l(1)

        self.send_reque st(h, handler, request_body)
        self.send_host( h, host)
        self.send_user_ agent(h)
        self.send_conte nt(h, request_body)

        errcode, errmsg, headers = h.getreply()

        if errcode != 200:
        raise ProtocolError(
        host + handler,
        errcode, errmsg,
        headers
        )

        self.verbose = verbose

        cookies = self.get_cookie s(headers)

        try:
        sock = h._conn.sock
        except AttributeError:
        sock = None

        response = self._parse_res ponse(h.getfile (), sock)
        if len(response) == 1:
        response = response[0]

        return response, cookies

        def _get_cookies(se lf, headers):
        import Cookie
        c = []
        for v in headers.gethead ers('set-cookie'):
        c.append(Cookie .SimpleCookie(v ))
        return c

        server = xmlrpclib.Serve rProxy("http://localhost:8000" ,
        transport=Cooki eTransport())
        result, cookies = server.somethin g.call()


        best,
        fw

        Comment

        • Milos Prudek

          #5
          Re: xmlrpc, extract data from http headers

          A better solution would be to extract cookies from headers in the
          request method and return them with response (see the code below). I
          Full solution! Wow! Thank you very much. I certainly do not deserve such
          kindness. Thanks a lot Filip!

          --
          Milos Prudek

          Comment

          • Filip Wasilewski

            #6
            Re: xmlrpc, extract data from http headers

            Milos Prudek wrote:
            A better solution would be to extract cookies from headers in the
            request method and return them with response (see the code below). I
            >
            Full solution! Wow! Thank you very much. I certainly do not deserve such
            kindness. Thanks a lot Filip!
            Glad to help. All in all this is the purpose of this group, isn't it?

            cheers,
            fw

            Comment

            Working...