1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Mechanize Error: "Unknown cookie jar file format"


The error "Unknown cookie jar file format" can be raised in one of two places, in Mechanize::CookieJar#save_as and Mechanize::CookieJar#load.

What Causes the Error?

Both of these methods take two arguments, a filename and a format. The format should be either the symbol :yaml or :cookiestxt. The :yaml argument obviously instructs Mechanize to save the cookie jar in YAML format, and :cookiestxt to save in Mozilla-compatible cookies.txt format. If the format argument is anything but these two symbols, it will raise the "Unknown cookie jar file format" error.

For instance, this will cause the error to be raised.

agent.cookie_jar.save_as('some_file', :unknownformat)

How do I Fix the Error?

Pass either :yaml or :cookiestxt as the second parameter to Mechanize::CookieJar#save_as or Mechanize::CookieJar#load. Alternatively, pass no second argument to the methods, as the default for the second argument is :yaml.

The following are valid ways to call Mechanize::CookieJar#save_as or Mechanize::CookieJar#load.

agent.cookie_jar.save_as('cookies.yaml', :yaml)
agent.cookie_jar.save_as('cookies.txt', :cookiestxt)

agent.cookie_jar.load('cookies.yaml', :yaml)
agent.cookie_jar.load('cookies.txt', :cookiestxt)
  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. The Mechanize 2.0 Handbook
  6. Mechanize Error: "Unknown cookie jar file format"

©2014 About.com. All rights reserved.