python mechanize session not saved
Question: I'm trying to use python mechanize to retrive the list of apps on iTunes
connect. Once this list is retrieved, further work will be done with those
links.

Logging in succeeds but then when i follow the "Manage Your Applications" link
I get redirected back to the login page. It is as if the session gets lost.

    
    
    import mechanize
    import cookielib
    from BeautifulSoup import BeautifulSoup
    import html2text
    
    filename = 'itunes.html'
    
    br = mechanize.Browser()
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)
    
    br.set_handle_equiv(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)
    
    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
    
    br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
    
    br.open('https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa')
    br.select_form(name='appleConnectForm')
    br.form['theAccountName'] = username
    br.form['theAccountPW'] = password
    
    br.submit()
    
    apps_link = br.find_link(text='Manage Your Applications')
    print "Manage Your Apps link = ", apps_link
    req = br.follow_link(text='Manage Your Applications')
    
    for app_link in br.links():
        print "link is ", app_link
    

Any ideas what could be wrong?


Answer: You need to
[save/load](http://docs.python.org/library/cookielib.html#cookielib.FileCookieJar.save)
the cookiejar

