Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52758

Re: How to keep cookies when making http requests (Python 2.7)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <fabiosantosart@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'urllib2': 0.07; 'cookie': 0.09; 'http': 0.09; 'subject:2.7': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'cookies': 0.16; 'cookies,': 0.16; 'exactly?': 0.16; 'subject:making': 0.16; 'subject:requests': 0.16; 'subject:when': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'server,': 0.19; 'help.': 0.21; 'seems': 0.21; 'example': 0.22; 'import': 0.22; 'aug': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; 'adds': 0.24; 'sends': 0.24; 'initial': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '&gt;': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'thus': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'subject: (': 0.35; "can't": 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'thanks': 0.36; 'should': 0.36; 'clear': 0.37; 'work?': 0.38; 'explain': 0.39; 'skip:& 20': 0.39; 'does': 0.39; 'how': 0.40; 'new': 0.61; 'to:addr:gmail.com': 0.65; 'response.': 0.68; 'request.': 0.70; 'yourself': 0.78; 'again!': 0.84; 'response,': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=irFiwDYYkfdQwyqsO3CuY2hmu13EACt/o/ftDz1+Lcg=; b=vAAFRbTkPSVPtiEWom3Ox/oBMh51/tu1pksnBzW1Ya50rk8UT4X9ua+eWRKBUdPe9/ d/k+PFVKmIgmsawTyBEwTbeWMYEEhC00xi5FthhopO9SESUrgPCks4d7YR4kchpduAgM a/I5HSxrPla5cIYZ7Q1V2i8io9L3K5TRmYdjz9SQw36zJUT9NFh3V1GxIZNOooPcIEL/ AJmXbMw9d1FkRShV3I39t4XIjlw3f9wMOHTNgTJP2W15EynyFtMFa3s2KgdnQPUk1bLo dtA9UxsyN0h7psKuhCHE2JU1Qc5idPcNHUVRE+tZ2qQq7o15mnTS+/OqAUFRmodCklZd AFJw==
MIME-Version 1.0
X-Received by 10.224.160.194 with SMTP id o2mr9532813qax.3.1377076525895; Wed, 21 Aug 2013 02:15:25 -0700 (PDT)
In-Reply-To <8266faf3-892b-4e49-9b38-87f0030250fc@googlegroups.com>
References <7e79a9b4-0bf9-4756-afd4-3bc127360b95@googlegroups.com> <mailman.67.1377065271.19984.python-list@python.org> <8266faf3-892b-4e49-9b38-87f0030250fc@googlegroups.com>
Date Wed, 21 Aug 2013 10:15:25 +0100
Subject Re: How to keep cookies when making http requests (Python 2.7)
From Fábio Santos <fabiosantosart@gmail.com>
To Luca Cerone <luca.cerone@gmail.com>
Content-Type multipart/alternative; boundary=089e01536d7a27b0d704e4719d1d
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.71.1377076529.19984.python-list@python.org> (permalink)
Lines 91
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377076529 news.xs4all.nl 15870 [2001:888:2000:d::a6]:57831
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52758

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 21 Aug 2013 09:22, "Luca Cerone" <luca.cerone@gmail.com> wrote:
>
> >
> > I have used "cookielib" externally to "urllib2". It looks
> >
> > like this:
> >
> > from urllib2 import urlopen, Request
> >
> > from cookielib import CookieJar
> > cookies = CookieJar()
> >
> > ....
> >
> > r = Request(...)
> >
> > cookies.add_cookie_header(r) # set the cookies
> >
> > R = urlopen(r, ...) # make the request
> >
> > cookies.extract_cookies(R, r) # remember the new cookies
>
> Hi Dieter,
> thanks a lot for the help.
> I am sorry but your code is not very clear to me.
> It seems that you are setting some cookies,
> but I can't understand how you use the ones that the site
> sends to you when you perform the initial request.

This example does both. The cookie jar adds the cookies to the http request
to be sent to the server, and updates the cookies from the response, if any
were sent. It seems pretty clear, seeing that it has a lot of comments.

The cookies from the site are thus in the cookie jar object after the call
to extract_cookies() extracts them from the response.

> Have you tried this code to check if this work?
> If it works as intended can you explain a bit better
> what it does exactly?

You should really test this yourself ;)

> Thanks again!
> Luca

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to keep cookies when making http requests (Python 2.7) Luca Cerone <luca.cerone@gmail.com> - 2013-08-20 15:24 -0700
  Re: How to keep cookies when making http requests (Python 2.7) dieter <dieter@handshake.de> - 2013-08-21 08:07 +0200
    Re: How to keep cookies when making http requests (Python 2.7) Luca Cerone <luca.cerone@gmail.com> - 2013-08-21 01:18 -0700
      Re: How to keep cookies when making http requests (Python 2.7) Fábio Santos <fabiosantosart@gmail.com> - 2013-08-21 10:15 +0100
      Re: How to keep cookies when making http requests (Python 2.7) dieter <dieter@handshake.de> - 2013-08-22 08:08 +0200
        Re: How to keep cookies when making http requests (Python 2.7) Luca Cerone <luca.cerone@gmail.com> - 2013-08-27 02:16 -0700
          Re: How to keep cookies when making http requests (Python 2.7) Luca Cerone <luca.cerone@gmail.com> - 2013-08-27 03:17 -0700
            Re: How to keep cookies when making http requests (Python 2.7) dieter <dieter@handshake.de> - 2013-08-28 06:52 +0200
              Re: How to keep cookies when making http requests (Python 2.7) Luca Cerone <luca.cerone@gmail.com> - 2013-08-30 05:01 -0700

csiph-web