issue with cookielib.LWPCookieJar

JD Smith jdsmith2816 at gmail.com
Fri Nov 30 22:14:12 CET 2007


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



More information about the Python-list mailing list