# Encoding problem ? in Mechanize /NET::Http.get

**URL:** <https://www.ruby-forum.com/t/encoding-problem-in-mechanize-net-http-get/161239>\
**Category:** Ruby\
**Created:** [February 24, 2009, 5:15pm UTC](https://www.ruby-forum.com/t/encoding-problem-in-mechanize-net-http-get/161239 "2009-02-24T17:15:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![reactorman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@reactorman](https://www.ruby-forum.com/u/reactorman)\
**Post date:** [February 24, 2009, 5:15pm UTC](https://www.ruby-forum.com/t/encoding-problem-in-mechanize-net-http-get/161239/1 "2009-02-24T17:15:19Z")

</div>

Hi there.  
I’m trying to get a site to mess with, using mechanize.  
Site charset is iso-8859-2 (central european something), Im running  
ubuntu 8.10 and ruby 1.8. (but it doesn’t seem to be the problem).  
During the process I get that rather unpleasant error

> ruby pierdolety.rb  
> /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/util.rb:29:in  
> `iconv': "\352</a></b></font>"... (Iconv::IllegalSequence) from /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/util.rb:29:in `to\_native\_charset’  
> from  
> /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/chain/response\_header\_handler.rb:29:in  
> `handle' from /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/chain.rb:30:in `pass’  
> from  
> /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/chain/handler.rb:6:in  
> `handle' from /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/chain/response_body_parser.rb:35:in `handle’  
> from  
> /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/chain.rb:30:in  
> `pass' from /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/chain/handler.rb:6:in `handle’  
> from  
> /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/chain/pre\_connect\_hook.rb:14:in  
> `handle' from /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/chain.rb:25:in `handle’  
> from  
> /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize.rb:494:in  
> `fetch_page' from /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize.rb:229:in `get’  
> from pierdolety.rb:9  
> Exit code: 1

from this code

require ‘rubygems’  
require ‘mechanize’

agent = WWW::Mechanize.new{ |agent|  
agent.user\_agent\_alias = ‘Mac Safari’}

agent.get(‘[http://www.land-serwis.pl/hurt/zaloguj.php](http://www.land-serwis.pl/hurt/zaloguj.php)’)

I tried googling it, but It gave Me no effect at all.

any ideas ?

---

<div class="post-metadata">

**Author:** ![reactorman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@reactorman](https://www.ruby-forum.com/u/reactorman)\
**Post date:** [February 24, 2009, 6:41pm UTC](https://www.ruby-forum.com/t/encoding-problem-in-mechanize-net-http-get/161239/2 "2009-02-24T18:41:32Z")

</div>

Adam Cza wrote:

> Hi there.  
> I’m trying to get a site to mess with, using mechanize.  
> Site charset is iso-8859-2 …  
> During the process I get that rather unpleasant error
> 
> > ruby pierdolety.rb  
> > /usr/lib/ruby/gems/1.8/gems/mechanize-0.9.1/lib/www/mechanize/util.rb:29:in  
> > `iconv’: “\352”… (Iconv::IllegalSequence)
> 
> from this code
> 
> require ‘rubygems’  
> require ‘mechanize’
> 
> agent = WWW::Mechanize.new{ |agent|  
> agent.user\_agent\_alias = ‘Mac Safari’}
> 
> agent.get(‘[Części Land Rover Freelander, Range Rover, Defender, Discovery | British Garage](http://www.land-serwis.pl/hurt/zaloguj.php)’)
> 
> I tried googling it, but It gave Me no effect at all.
> 
> any ideas ?

Looking at the source code from that web site, mechanize is having  
problems with this word:

SiÄ™

The \352 in the error message is an octal number, which is 234 in  
decimal, which is the decimal code for ‘Ä™’ in iso-8859-2. Mechanize is  
choking on that character. The error message mentions iconv, which is a  
standard library module used to convert between different encodings. It  
looks to me like get() is trying to use iconv to convert ‘Ä™’ to ascii,  
which is causing the error.

I looked around the Mechanize docs, and I couldn’t find any mention of  
“encoding”, so I have no solution.
