By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

issue with cookielib.LWPCookieJar

P: n/a
Greetings:

My cookiejar contains the cookie that I need however when I do
cj.save(file) it does not actually save out to the cookies.lwj Does
anyone have any clue what would keep this from saving? It CREATED my
cookies.lwj file so I know it's not permissions.

cookies.lwp:
#LWP-Cookies-2.0
test.py:
def requestXML(frag, server='US', data=None):
import urllib
import urllib2
import os.path
import cookielib

base_urls = {
"US":"http://www.wowarmory.com/",
"EU":"http://eu.wowarmory.com/",
"US_SECURE":"https://www.wowarmory.com/",
"EU_SECURE":"https://eu.wowarmory.com/"
}

COOKIEFILE = 'cookies.lwp'
cj = cookielib.LWPCookieJar()

if os.path.isfile(COOKIEFILE):
cj.load(COOKIEFILE)

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(c j))

try:
if data is not None:
data = urllib.urlencode(data)

req = urllib2.Request(base_urls[server] + frag, data)
req.add_header('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT
6.0; en-US; rv:1.8.1.10) Gecko/20071115 Firefox/2.0.0.10')
handle = opener.open(req)
except IOError, e:
if hasattr(e, 'code'):
return 'We failed to open "%s".' % base_urls[server] + frag
elif hasattr(e, 'reason'):
return "The error object hast he following 'reason' attribute:
%s" % e.reason

headers = handle.info()
xml = handle.read()
print xml
print headers
print data

for index, cookie in enumerate(cj):
print index, ' : ', cookie
Nov 30 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
JD Smith <jd*********@gmail.comwrites:
Greetings:

My cookiejar contains the cookie that I need however when I do
cj.save(file) it does not actually save out to the cookies.lwj Does
anyone have any clue what would keep this from saving? It CREATED my
cookies.lwj file so I know it's not permissions.
You want a true ignore_discard argument to .save() and .load() (or
..revert()).
John
Dec 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.