issue with cookielib.LWPCookieJar

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


My cookiejar contains the cookie that I need however when I do 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.

def requestXML(frag, server='US', data=None):
  import urllib
  import urllib2
  import os.path
  import cookielib

  base_urls = {

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

  if os.path.isfile(COOKIEFILE):

  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

    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: Gecko/20071115 Firefox/')
    handle =
  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 =
  xml =
  print xml
  print headers
  print data

  for index, cookie in enumerate(cj):
    print index, '  :  ', cookie

More information about the Python-list mailing list