How to enable cookies in python engine?

I am trying to submit a form using mechanization.

Python

import mechanize
import Cookie
import cookielib

cookiejar =cookielib.LWPCookieJar()
br = mechanize.Browser()
br.set_cookiejar(cookiejar)
br.set_handle_robots(False) 
br.open("https://<website url>")
assert br.viewing_html()
br.select_form(name="signinWidget") 
br["username"] = "<username>"
br["password"] = "<password>"
homePage = br.submit()
return homePage

      

I am getting this message back:

<body>
    <div id="ap_error_page_cookieless_wrapper" class="ap_error_page_cookieless_wrapper">
       <div id="ap_error_page_cookieless_title" class="ap_error_page_cookieless_title">
         <h1>Please Enable Cookies to Continue</h1>
       </div>
       <div id="ap_error_page_cookieless_message" class="ap_error_page_cookieless_message">              
    <p> To continue shopping at Amazon, please enable cookies in your Web browser.
    <a href="/gp/help/customer/display.html/ref=ap_cookie_error_help??nodeId=200168080" target="AmazonHelp" onclick="return amz_js_PopWin(this.href,'AmazonHelp','width=700,height=800,resizable=1,scrollbars=1,toolbar=1,status=1');return false;">
      Learn more
    </a>        
    about cookies and how to enable them.</p>      
    <p> Once you have enabled cookies in your browser, please click on the button below to return to the previous page.</p>
  </div>
  <div id="ap_error_return_home" class="ap_error_return_home">    
    <p>
</body>

      

Why isn't the cookie jar working? I've tried several other ways, but nothing works. Can I do the same using a query? How> Help. Thank!

+3


source to share





All Articles