From ngrandy at gmail.com Sat May 3 04:27:31 2008 From: ngrandy at gmail.com (Nick Grandy) Date: Sat, 3 May 2008 01:27:31 -0700 Subject: [Mechanize-users] marshalling mechanized Message-ID: <9a6cef0c0805030127p38008ac5mbe218f4d186520f8@mail.gmail.com> hi all, in the course of my hacking i wanted to marshal mechanized objects (whether the agent, page, or other). this may be a rather particular use-case, but i figured i would report. marshalling does not work on certain objects, in particular IO objects, and since mechanized uses Net::HTTP it makes use of IO objects. so it turns out that it you just do a = WWW::Mechanize.new page = a.get "http://nytimes.com" Marhshal.dump(a) you get a problem. in particular, "TypeError: can't dump TCPSocket". basically, don't try to marshal a socket. however, if we make sure to finish the http connection after each use, then the agent can be marshalled safely. i accomplished this by inserting: http_obj.finish immediately prior to this line: return page if res_klass <= Net::HTTPSuccess in mechanize.rb, which is approximately line 587 in v 0.7.0 this is a crude hack that doesn't, i think, respect keep-alive connections, but it does at least work for the purpose of ensuring the agent can be marshalled. i invite thoughts on more elegant solutions! nick