issue with cookielib.LWPCookieJar

J

JD Smith

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(cj))

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
 
J

John J. Lee

JD Smith said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top