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: 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: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: newbie needs help with cookielib Thread-Index: AcwKOoI4qxuLRBdWQeSB1eqkaosFTgAQyjoQ References: From: "Sells, Fred" To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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=20 ... 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 =3D cookielib.MozillaCookieJar() cj.load('C:/Users/myname/Desktop/cookies.txt') opener =3D urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) r =3D opener.open("http://daffyduck.mydomain.org/wsgi/myapp.wsgi") = print r.read()=20 return