在尝试形成POST查询时,机械化Iconv :: IllegalSequence

时间:2009-08-24 18:04:26

标签: ruby encoding mechanize

以下代码引发了上述错误,我该如何解决?

require 'mechanize'
m = WWW::Mechanize.new
p = m.get('http://art-mobile.com.ua/register.php')
f = p.forms.first
f.submit(f.buttons.last)

以防万一,这是我的方框上的错误的完整描述

D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/util.rb:40:in `iconv': "Ðåãèñòðàöèÿ"... (Iconv::IllegalSequence)
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/util.rb:40:in `from_native_charset'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:152:in `from_native_charset'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:144:in `block in proc_query'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:143:in `map'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:143:in `proc_query'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:198:in `block in build_query'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:197:in `each'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:197:in `build_query'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:214:in `request_data'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize.rb:401:in `post_form'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize.rb:344:in `submit'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:130:in `submit'
    from D:/doer.rb:8:in `<main>'

BTW this solution不起作用

1 个答案:

答案 0 :(得分:0)

看起来解决方案是稍微重写gem,以便在初始化新页面时将页面编码转换为utf-8,将@encoding var更改为utf-8并将原始编码存储在另一个文件中,并进行必要的更改以强制gem在形成查询时使用原始编码