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


Groups > comp.lang.python > #4633

newbie needs help with cookielib

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <fred.sells@adventistcare.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '2.7': 0.05; 'fine,': 0.07; 'urllib2': 0.07; 'python': 0.07; 'googled': 0.09; 'def': 0.13; 'starts': 0.15; 'apps.': 0.16; 'fp)': 0.16; 'hdrs,': 0.16; 'msg,': 0.16; 'pointers': 0.16; 'url:mydomain': 0.16; 'subject:help': 0.19; 'greatly': 0.20; 'code,': 0.20; 'header:In-Reply-To:1': 0.22; '2.4': 0.23; 'script.': 0.23; "i'm": 0.26; 'looks': 0.28; 'raise': 0.29; 'error': 0.29; 'server': 0.29; 'skip:" 30': 0.29; 'this.': 0.30; 'confused': 0.31; 'robust': 0.31; "skip:' 10": 0.32; 'to:addr:python-list': 0.32; "i've": 0.33; 'test': 0.33; 'uses': 0.34; 'using': 0.34; 'received:192': 0.34; 'got': 0.34; 'file': 0.35; 'normally': 0.35; 'print': 0.35; '4.0': 0.35; 'box.': 0.35; 'hoping': 0.36; 'appreciated.': 0.36; 'session': 0.36; 'charset:us-ascii': 0.36; 'received:192.168': 0.37; 'some': 0.37; 'either': 0.37; 'subject:with': 0.37; 'http': 0.38; 'security.': 0.38; 'but': 0.38; 'url:org': 0.38; 'received:org': 0.38; 'docs': 0.39; 'somewhat': 0.39; 'set': 0.39; 'to:addr:python.org': 0.39; 'add': 0.39; 'basic': 0.40; 'solution': 0.40; 'would': 0.40; 'skip:h 20': 0.60; 'production': 0.65; 'login': 0.68; 'opener': 0.84; 'need,': 0.91
x-mimeole Produced By Microsoft Exchange V6.5
Content-class urn:content-classes:message
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
Subject newbie needs help with cookielib
Date Wed, 4 May 2011 13:16:40 -0400
In-Reply-To <BANLkTinJ-u7dz3wJ2HJzKo0aK83UCSgswQ@mail.gmail.com>
X-MS-Has-Attach
X-MS-TNEF-Correlator
Thread-Topic newbie needs help with cookielib
Thread-Index AcwKOoI4qxuLRBdWQeSB1eqkaosFTgAQyjoQ
References <mailman.974.1304041735.9059.python-list@python.org><c63e7579-16d1-4bfa-8486-8ab791343dba@glegroupsg2000goo.googlegroups.com><BANLkTik1V3CwUY41-F0U3nxhFV=j2Bvk1g@mail.gmail.com><BANLkTinOWxFtq-cSCk18d7HbKUYAyLCp9g@mail.gmail.com> <BANLkTinJ-u7dz3wJ2HJzKo0aK83UCSgswQ@mail.gmail.com>
From "Sells, Fred" <fred.sells@adventistcare.org>
To <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.1159.1304529452.9059.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 82.94.164.166
X-Trace 1304529452 news.xs4all.nl 41110 [::ffff:82.94.164.166]:43676
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4633

Show key headers only | View raw


I'm using Python 2.4 and 2.7 for different apps.  I'm happy with a
solution for either one.

I've got to talk to a url that uses a session cookie.  I only need to
set this when I'm developing/debugging so I don't need a robust
production solution and I'm somewhat confused by the docs on cookielib.
I can use urllib2 without cookielib just fine, but need the cookie to
add some security.

I'm normally using Firefox 4.0 to login to the server and get the
cookie.  After that I need some way to set the same cookie in my python
script.  I can do this by editing my code, since I only need it while
defeloping from my test W7 box.


I was hoping to find something like

...set_cookie('mycookiename', 'myvalue', 'mydomain.org')

I've googled this most of the morning and found everything but what I
need, or I just don't understand the basic concept.  Any pointers would
be greatly appreciated.  One of my false starts looks like this. But I
get a 

...
  File "C:\alltools\python26\lib\urllib2.py", line 518, in
http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Access Deinied

def test1():
    cj = cookielib.MozillaCookieJar()
    cj.load('C:/Users/myname/Desktop/cookies.txt')
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    r = opener.open("http://daffyduck.mydomain.org/wsgi/myapp.wsgi")   
    print r.read() 
    return

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


Thread

Re: Aborting Python from C code Miki Tebeka <miki.tebeka@gmail.com> - 2011-04-30 01:08 -0700
  Re: Aborting Python from C code Chris Angelico <rosuav@gmail.com> - 2011-04-30 18:17 +1000
  Re: Aborting Python from C code Chris Angelico <rosuav@gmail.com> - 2011-05-04 19:02 +1000
  newbie needs help with cookielib "Sells, Fred" <fred.sells@adventistcare.org> - 2011-05-04 13:16 -0400

csiph-web