Hi all,<br><br>I&#39;ve been using mechanize for a while and it rocks. Docs are pretty clear and so far I&#39;ve been able to do it on my own.<br>However, I&#39;m stuck in a weird situation in a script to download my contact list from hotmail. 
<br>I&#39;ve used Firebug to check all urls, and tested it by hand while logged in via browser.<br>Even in the script everything works well until the last &#39;agent.get_file&#39;, which gets stuck with a weird error:<br>
<br>------ snip ------<br>$ ruby msn-scrap.rb <br>#&lt;URI::HTTP:0xfdbc850b8 URL:<a href="http://by124w.bay124.mail.live.com/mail/TodayLight.aspx?&amp;n=1573603203&amp;gs=true">http://by124w.bay124.mail.live.com/mail/TodayLight.aspx?&amp;n=1573603203&amp;gs=true
</a>&gt;<br>&quot;<a href="http://by124w.bay124.mail.live.com/mail/GetContacts.aspx">http://by124w.bay124.mail.live.com/mail/GetContacts.aspx</a>&quot;<br>Err: unexpected end of file<br>Trace:<br>/usr/lib/ruby/1.8/mechanize.rb:372:in `read&#39;
<br>/usr/lib/ruby/1.8/mechanize.rb:372:in `fetch_page&#39;<br>/usr/lib/ruby/1.8/net/http.rb:1050:in `request&#39;<br>/usr/lib/ruby/1.8/net/http.rb:2133:in `reading_body&#39;<br>/usr/lib/ruby/1.8/net/http.rb:1049:in `request&#39;
<br>/usr/lib/ruby/1.8/mechanize.rb:345:in `fetch_page&#39;<br>/usr/lib/ruby/1.8/net/http.rb:543:in `start&#39;<br>/usr/lib/ruby/1.8/mechanize.rb:339:in `fetch_page&#39;<br>/usr/lib/ruby/1.8/mechanize.rb:139:in `get&#39;<br>
/usr/lib/ruby/1.8/mechanize.rb:146:in `get_file&#39;<br>msn-scrap.rb:32<br>----- snip ------<br><br>mech.log important part:<br><br>D, [2007-11-12T12:22:35.925521 #24540] DEBUG -- : request-header: referer =&gt; <a href="http://by124w.bay124.mail.live.com/mail/TodayLight.aspx?&amp;n=1573603203&amp;gs=true">
http://by124w.bay124.mail.live.com/mail/TodayLight.aspx?&amp;n=1573603203&amp;gs=true</a><br>D, [2007-11-12T12:22:36.589708 #24540] DEBUG -- : response-header: cache-control =&gt; private,max-age=86400<br>D, [2007-11-12T12:22:
36.589853 #24540] DEBUG -- : response-header: vary =&gt; Accept-Encoding<br>D, [2007-11-12T12:22:36.589934 #24540] DEBUG -- : response-header: connection =&gt; keep-alive<br>D, [2007-11-12T12:22:36.590012 #24540] DEBUG -- : response-header: expires =&gt; Wed, 01 Jan 1997 12:00:00 GMT, Wed, 01 Jan 1997 12:00:00 GMT
<br>D, [2007-11-12T12:22:36.590089 #24540] DEBUG -- : response-header: p3p =&gt; CP=&quot;BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo&quot;<br>D, [2007-11-12T12:22:36.590166 #24540] DEBUG -- : response-header: date =&gt; Mon, 12 Nov 2007 14:28:34 GMT
<br>D, [2007-11-12T12:22:36.590241 #24540] DEBUG -- : response-header: xxn =&gt; W4<br>D, [2007-11-12T12:22:36.590344 #24540] DEBUG -- : response-header: content-type =&gt; text/csv<br>D, [2007-11-12T12:22:36.590430 #24540] DEBUG -- : response-header: msnserver =&gt; H: BAY124-W4 V: 
12.0.1190.927 D: 2007-09-27T23:27:08<br>D, [2007-11-12T12:22:36.590509 #24540] DEBUG -- : response-header: content-encoding =&gt; gzip<br>D, [2007-11-12T12:22:36.590586 #24540] DEBUG -- : response-header: content-disposition =&gt; attachment; filename=&quot;
WLMContacts.csv&quot;<br>D, [2007-11-12T12:22:36.590663 #24540] DEBUG -- : response-header: server =&gt; Microsoft-IIS/6.0<br>D, [2007-11-12T12:22:36.590738 #24540] DEBUG -- : response-header: content-length =&gt; 4285<br>
D, [2007-11-12T12:22:36.591732 #24540] DEBUG -- : gunzip body<br><br>I&#39;ve tried some ugly hacks, as altering headers and so on (BTW, how do I change request-headers w/o inheriting from www::mechanize ?), but no result.
<br><br>Am I doing something wrong ? Seems to me that the server encodes the file (Firebug shows it too), but mechanize receives a weird error while trying to fetch it. Any ideas ?<br><br>I did another contact scrap for gmail and it worked wonders. There is a post of mine at 
<a href="http://zenmachine.wordpress.com">http://zenmachine.wordpress.com</a> where I show how to use firebug and mechanize to find the right URLs.<br><br><br><br>Best regards, and keep up the excellent work.<br><br><br>---- 
msn-scrap.rb----<br><br>#!/usr/bin/env ruby<br><br># download msn contacts<br><br>require &#39;rubygems&#39;<br>require &#39;mechanize&#39;<br>require &#39;logger&#39;<br><br>begin<br>&nbsp;&nbsp;&nbsp; agent = WWW::Mechanize.new { |a| 
a.log = Logger.new(&quot;mech.log&quot;) }<br>&nbsp;&nbsp;&nbsp; agent.user_agent_alias&nbsp; = &quot;Windows IE 6&quot;<br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; page = agent.get(&quot;<a href="https://login.live.com/login.srf">https://login.live.com/login.srf</a>
&quot;)<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; form = page.forms.name(&quot;f1&quot;).first<br>&nbsp;&nbsp;&nbsp; form.login = &#39;user&#39;<br>&nbsp;&nbsp;&nbsp; form.passwd = &#39;pass&#39;<br><br>&nbsp;&nbsp;&nbsp; page = agent.submit(form)<br><br>&nbsp;&nbsp;&nbsp; pageContact = agent.get
(&#39;<a href="http://g.live.com/1MBAMen-us/sc_mail&#39;">http://g.live.com/1MBAMen-us/sc_mail&#39;</a>)<br>&nbsp;&nbsp;&nbsp; p pageContact.uri<br><br>&nbsp;&nbsp;&nbsp; baseURL=pageContact.uri.host<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; contactURL=&#39;http://&#39;+baseURL+&#39;/mail/GetContacts.aspx&#39;
<br>&nbsp;&nbsp;&nbsp; p contactURL<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; page = agent.get_file(contactURL)<br><br>&nbsp;&nbsp;&nbsp; p page<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; if (page.code == &#39;200&#39;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; puts &quot;saving contacts.csv&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; page.save_as(&#39;contacts_msn.csv&#39;)
<br>&nbsp;&nbsp;&nbsp; else<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; puts &quot;error downloading contacts&quot;<br>&nbsp;&nbsp;&nbsp; end<br><br><br>&nbsp;&nbsp;&nbsp; <br>rescue<br>&nbsp;&nbsp;&nbsp; puts &quot;Err: &quot;+$!<br>&nbsp;&nbsp;&nbsp; puts &quot;Trace:&quot;<br>&nbsp;&nbsp;&nbsp; $@.each {|tl| <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; puts tl<br>&nbsp;&nbsp;&nbsp; }<br>
end<br><br clear="all"><br>-- <br>More cowbell, please !