librelist archives

« back to archive

Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2009-12-16 @ 13:49
Dear Shoes folk,

I wonder if you could help me out. I'm trying to get Mechanize and Ruby 1.9
based Shoes to play nicely together. Here is a very simple app:

http://gist.github.com/257819

These are the results on Windows XP, both Mechanize 0.9.3 and 0.8.5 tested:
* Shoes Policeman 1271 (built with Ruby 1.9) - I get the error
"Uninitialized constant Encoding::US_ASCII" in the console.
* Shoes Policeman 1229 (built on Ruby 1.8) - Works correctly
* Shoes Raisins 1134 - Works correctly

Is this something to do with the fact that Ruby 1.8 wasn't UTF-8 aware, but
_why hacked it so it was for Shoes. And then along comes Ruby 1.9 which can
deal with lots of encodings, and perhaps something is now a bit wonky in the
Shoes code?

Both versions of Mechanize work fine in my Windows Ruby 1.9 install. So
seems to me that this is specific to Shoes.

Kind regards,

i5m

-----------------------
i5m.co.uk
GPG Key: 0xA18A602B

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
pete
Date:
2009-12-16 @ 20:25
On Wed, Dec 16, 2009 at 5:49 AM, i5m <i5ivem@googlemail.com> wrote:

> Dear Shoes folk,
>
> I wonder if you could help me out. I'm trying to get Mechanize and Ruby 1.9
> based Shoes to play nicely together. Here is a very simple app:
>
> http://gist.github.com/257819
>
> These are the results on Windows XP, both Mechanize 0.9.3 and 0.8.5 tested:
> * Shoes Policeman 1271 (built with Ruby 1.9) - I get the error
> "Uninitialized constant Encoding::US_ASCII" in the console.
> * Shoes Policeman 1229 (built on Ruby 1.8) - Works correctly
> * Shoes Raisins 1134 - Works correctly
>
> Is this something to do with the fact that Ruby 1.8 wasn't UTF-8 aware, but
> _why hacked it so it was for Shoes. And then along comes Ruby 1.9 which can
> deal with lots of encodings, and perhaps something is now a bit wonky in the
> Shoes code?
>
> Both versions of Mechanize work fine in my Windows Ruby 1.9 install. So
> seems to me that this is specific to Shoes.
>
> Kind regards,
>
> i5m
>
> -----------------------
> i5m.co.uk
> GPG Key: 0xA18A602B
>

I tried this on my Windows  XP VM with Shoes 1278 (the latest from here:
http://www.rin-shun.com/shoes/), and I get the error "Code converter not
found (UTF-8 to ASCII-8BIT)".

Are these experimental Shoes builds archived anywhere?

pete

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
pete
Date:
2009-12-16 @ 20:27
On Wed, Dec 16, 2009 at 12:25 PM, pete <pete@peterhiggins.org> wrote:

> On Wed, Dec 16, 2009 at 5:49 AM, i5m <i5ivem@googlemail.com> wrote:
>
>> Dear Shoes folk,
>>
>> I wonder if you could help me out. I'm trying to get Mechanize and Ruby
>> 1.9 based Shoes to play nicely together. Here is a very simple app:
>>
>> http://gist.github.com/257819
>>
>> These are the results on Windows XP, both Mechanize 0.9.3 and 0.8.5
>> tested:
>> * Shoes Policeman 1271 (built with Ruby 1.9) - I get the error
>> "Uninitialized constant Encoding::US_ASCII" in the console.
>> * Shoes Policeman 1229 (built on Ruby 1.8) - Works correctly
>> * Shoes Raisins 1134 - Works correctly
>>
>> Is this something to do with the fact that Ruby 1.8 wasn't UTF-8 aware,
>> but _why hacked it so it was for Shoes. And then along comes Ruby 1.9 which
>> can deal with lots of encodings, and perhaps something is now a bit wonky in
>> the Shoes code?
>>
>> Both versions of Mechanize work fine in my Windows Ruby 1.9 install. So
>> seems to me that this is specific to Shoes.
>>
>> Kind regards,
>>
>> i5m
>>
>> -----------------------
>> i5m.co.uk
>> GPG Key: 0xA18A602B
>>
>
> I tried this on my Windows  XP VM with Shoes 1278 (the latest from here:
> http://www.rin-shun.com/shoes/), and I get the error "Code converter not
> found (UTF-8 to ASCII-8BIT)".
>
> Are these experimental Shoes builds archived anywhere?
>
> pete
>

I forgot to mention, I also tried adding the "magic comment" to the top of
your script and got the same result.

pete

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2009-12-17 @ 10:38
Pete,

thanks for taking a look. I just installed that rin-shun build and noticed
that it didn't come with openssl; missing:


* ruby\lib\openssl.rb
* ruby\lib\openssl\*
* ruby\lib\i386-mswin32\openssl.so

And also:

* ruby\gems\1.9.1\hpricot-0.8.1\lib\fast_xs.so
* ruby\gems\1.9.1\hpricot-0.8.1\lib\hpricot_scan.so

(I've noticed these hpricot .so files being missing when I've built shoes
before, but haven't tracked down why it happens). So I'm surprised the code
worked at all for you with those files missing.

On Wed, Dec 16, 2009 at 8:25 PM, pete <pete@peterhiggins.org> wrote:

>
>> I tried this on my Windows  XP VM with Shoes 1278 (the latest from here:
> http://www.rin-shun.com/shoes/), and I get the error "Code converter not
> found (UTF-8 to ASCII-8BIT)".
>
>
When I copied all them over I get the exact same error I got before
(Encoding::US_ASCII... etc) when testing with mechanise 0.8.5.

Weird.



> Are these experimental Shoes builds archived anywhere?
>
> pete
>


The builds I referred to are just ones I've built. I don't have them
uploaded anywhere.


-----------------------
i5m.co.uk
GPG Key: 0xA18A602B

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
Satoshi Asakawa
Date:
2009-12-16 @ 17:15
Hi i5m,

> Both versions of Mechanize work fine in my Windows Ruby 1.9 install.
Cool!

I'm using this on my Windows XP laptop:
  - ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-mswin32]

and the following gems installed:
  - mechanize-0.9.3
  - nokogiri-1.4.1-x86-mswin32

But I got this error. Not using Shoes, just ran one line: require
'mechanize' with ruby.

c:/ruby/lib/ruby/1.9.1/net/https.rb:102:in `require': no such file to load
-- openssl (LoadError)
    from c:/ruby/lib/ruby/1.9.1/net/https.rb:102:in `<top (required)>'
    from
c:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize.rb:2:in
`require'
    from
c:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize.rb:2:in
`<top (required)>'
    from
c:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/mechanize.rb:7:in
`require'
    from
c:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/mechanize.rb:7:in `<top
(required)>'
    from test.rb:1:in `require'
    from test.rb:1:in `<main>'

Umm... will you give me some suggestions?

ashbb

# Sorry, no information about your problem...

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2009-12-17 @ 15:50
Ashbb,

if you are building Ruby yourself, you'll need to look at this page:

http://www.garbagecollect.jp/ruby/mswin32/en/documents/install.html

to get openssl installed.

-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Wed, Dec 16, 2009 at 5:15 PM, Satoshi Asakawa <ashbbb@gmail.com> wrote:

>
> I'm using this on my Windows XP laptop:
>   - ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-mswin32]
>
> But I got this error. Not using Shoes, just ran one line: require
> 'mechanize' with ruby.
>
> c:/ruby/lib/ruby/1.9.1/net/https.rb:102:in `require': no such file to load
> -- openssl (LoadError)
>
> Umm... will you give me some suggestions?
>
> ashbb
>

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
Satoshi Asakawa
Date:
2009-12-17 @ 16:01
Hi i5m,

Thanks!
I was forgetting that I couldn't install openssl before. xx-P

After some googling I got a solution.
http://wso2.org/forum/thread/3861

I guess I'll be able to build openssl and remake deps for Shoes.

I'll try asap. Please give me some time. ;-)

ashbb

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
Satoshi Asakawa
Date:
2009-12-17 @ 19:12
Just uploaded a new deps included openssl and iconv.
And rebuilt Shoes-0.r1278 with that deps.

You can download from here: http://www.rin-shun.com/shoes/index.html

Then I copied two gems into Shoes by hand.
 - mechanize-0.9.3
 - nokogiri-1.4.1-x86-mswin32

At last I got the error: "Uninitialized constant Encoding::US_ASCII"

Then I got the trace with this snippet (test.rb).

require 'mechanize'

Shoes.app do
  Agent = WWW::Mechanize.new
  page = Agent.get('http://www.google.com/') \
    rescue open('debug.txt', 'w'){|f| f.puts "#{$!.class.name}:
#{$!.message}\n#{$!.backtrace.join("\n")}"}
  para page.body
end

-----
NameError: uninitialized constant Encoding::US_ASCII
C:/build/shoes/dist/ruby/lib/uri/common.rb:226:in `escape'
C:/build/shoes/dist/ruby/lib/uri/common.rb:504:in `escape'

C:/build/shoes/dist/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/chain/uri_resolver.rb:29:in
`block in handle'

C:/build/shoes/dist/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/chain/uri_resolver.rb:26:in
`map'

C:/build/shoes/dist/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/chain/uri_resolver.rb:26:in
`handle'

C:/build/shoes/dist/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/chain.rb:25:in
`handle'

C:/build/shoes/dist/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize.rb:457:in
`fetch_page'

C:/build/shoes/dist/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize.rb:238:in
`get'
test.rb:5:in `block in <main>'
(eval):1:in `instance_eval'
(eval):1:in `block in <main>'
test.rb:3:in `call'
test.rb:3:in `app'
test.rb:3:in `<main>'
C:/build/shoes/dist/lib/shoes.rb:392:in `eval'
C:/build/shoes/dist/lib/shoes.rb:392:in `visit'
C:/build/shoes/dist/lib/shoes.rb:105:in `show_selector'
C:/build/shoes/dist/lib/shoes.rb:135:in `block (4 levels) in splash'
Resolv::DNS::Resource:0:in `call'

Hope this helps,
ashbb

# Oops, 4am now. Need some sleep...

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2009-12-18 @ 10:34
ashbb,

Ok, thanks to that debugging, I don't actually think the error is to do with
Mechanize. See below.

On Thu, Dec 17, 2009 at 7:12 PM, Satoshi Asakawa <ashbbb@gmail.com> wrote:

>
> Then I got the trace with this snippet (test.rb).
>
>
> -----
> NameError: uninitialized constant Encoding::US_ASCII
> C:/build/shoes/dist/ruby/lib/uri/common.rb:226:in `escape'
>


Ok, on this line in common.rb it says:

end.force_encoding(Encoding::US_ASCII)

I just tried another simple app:

Shoes.app do

    debug Encoding.list #Try .name_list as well

end


I expected this just to return UTF-8, but oddly I got:

"[#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>, #<Encoding:US_ASCII>]".

So I'm more confused now:

Shoes.app do

    para Encoding::US_ASCII

end


Gets the error "uninitialized constant Encoding::US_ASCII"

Shoes.app do

    debug Encoding.find("US_ASCII")

end


Gets the error "unknown encoding name - US_ASCII

????

I'm utterly confused.


-----------------------
i5m.co.uk
GPG Key: 0xA18A602B

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2009-12-18 @ 11:18
How exactly does/did Shoes make Ruby UTF-8 aware? I've not figured it out
from the source code yet. But I'm guessing there's something there that
needs to change for Ruby 1.9

Also, Is this just a windows problem?
-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Fri, Dec 18, 2009 at 10:34 AM, i5m <i5ivem@googlemail.com> wrote:

> I just tried another simple app:
>
> Shoes.app do
>
>     debug Encoding.list #Try .name_list as well
>
> end
>
>
> I expected this just to return UTF-8, but oddly I got:
>
> "[#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>, #<Encoding:US_ASCII>]".
>
>
> Shoes.app do
>
>     debug Encoding.find("US_ASCII")
>
> end
>
>
> Gets the error "unknown encoding name - US_ASCII
>
> ????
>

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
Anuj Dutta
Date:
2009-12-18 @ 11:40
2009/12/18 i5m <i5ivem@googlemail.com>

> How exactly does/did Shoes make Ruby UTF-8 aware? I've not figured it out
> from the source code yet. But I'm guessing there's something there that
> needs to change for Ruby 1.9
>
> Also, Is this just a windows problem?
>
> -----------------------
> i5m.co.uk
> GPG Key: 0xA18A602B
>
>
> On Fri, Dec 18, 2009 at 10:34 AM, i5m <i5ivem@googlemail.com> wrote:
>
>> I just tried another simple app:
>>
>> Shoes.app do
>>
>>     debug Encoding.list #Try .name_list as well
>>
>> end
>>
>>
>> I expected this just to return UTF-8, but oddly I got:
>>
>> "[#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>, #<Encoding:US_ASCII>]".
>>
>>
>>  Shoes.app do
>>
>>     debug Encoding.find("US_ASCII")
>>
>> end
>>
>>
>> Gets the error "unknown encoding name - US_ASCII
>>
>> ????
>>
>

Hello all,

I have been MIA lately, but catching up with the mailing-list now.

Hey i5m,

I have the same issue on Mac. I just ran your code.

Anuj

-- 
Anuj DUTTA

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2009-12-23 @ 07:32
Anuj,



On 18 Dec 2009, at 11:40, Anuj Dutta wrote:

>
>
> I have the same issue on Mac. I just ran your code.
>
> Anuj
>
> --  
> Anuj DUTTA

That's interesting, as I've just had a chance to test on OSX PPC and  
it works fine. I.e. this little app:

Shoes.app do
     para Encoding::US_ASCII
end

returns "US-ASCII" in the window.

And I would have though OSX Intel and PPC would be the same.



-----------------------
i5m.co.uk
GPG Key: 0xA18A602B

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
Satoshi Asakawa
Date:
2009-12-18 @ 19:01
Hi i5m again,

> How exactly does/did Shoes make Ruby UTF-8 aware?
Are you looking for the following?

http://github.com/shoes/shoes/blob/master/lib/shoes.rb#L400-406

Regards,
ashbb

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
Satoshi Asakawa
Date:
2009-12-19 @ 16:50
Hi all,

After remaking the deps files and adding a monkey patch, my local
Shoes-0.r1279 for Windows works with Mechanize.

Look at a little note:
http://github.com/ashbb/shoes_hack_note/blob/master/md/hack015.md

Have to improve the structure of deps files and revise the Rakefile to use
Ruby 1.9 correctly, I think...

But now, anyway it works as a tentative solution. ;-)

ashbb

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2009-12-23 @ 07:36
ashbb,

thanks very much - an early Christmas present for me. I can't verify  
on Windows until the new year, but it sounds like I'll finally be able  
to move my app to a Shoes Policeman build.

On 19 Dec 2009, at 16:50, Satoshi Asakawa wrote:

> Hi all,
>
> After remaking the deps files and adding a monkey patch, my local  
> Shoes-0.r1279 for Windows works with Mechanize.
>
> Look at a little note: 
http://github.com/ashbb/shoes_hack_note/blob/master/md/hack015.md
>

When you said:

On 18 Dec 2009, at 18:55, Satoshi Asakawa wrote:

> Hi i5m,
>
> > Gets the error "unknown encoding name - US_ASCII
> Try to use "US-ASCII" instead of "US_ASCII".

I didn't think the fix would be that easy! I'm still not sure I  
understand why this happens. If you've seen my other message about OSX  
PPC you'll see that it doesn't suffer from the same issue.


Regards,

i5m
-----------------------
i5m.co.uk
GPG Key: 0xA18A602B

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2010-01-29 @ 10:53
ashbb and all,

I've not been doing much Shoes stuff so far this year, been trying to learn
a bit of Java. Meant to reply to this sooner:

On Wed, Dec 23, 2009 at 7:36 AM, i5m <i5ivem@googlemail.com> wrote:

> ashbb,
>
> thanks very much - an early Christmas present for me. I can't verify on
> Windows until the new year, but it sounds like I'll finally be able to move
> my app to a Shoes Policeman build.
>

I spoke too soon.  Although ashbb's fixes do solve the sample Mechanize
problem I was having, I am still having encoding issues in my actual app.

Error on <unknown> line 0 "uninitialised constant Encoding::UTF_16BE

Unfortunately I don't have any more information yet. I need to track down
where the error is occurring in my app and then in Shoes. But this is just
to let you know we've not got to the bottom of the encoding issues yet :-(

-----------------------
i5m.co.uk
GPG Key: 0xA18A602B

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2010-01-06 @ 11:16
ashbb,

which is the best way to permanently fix this?

1) Leave the deps as 'pure' Ruby 1.9 and use the Rakefile to change the
source code
2) Make the mods to Ruby 1,9 in the deps.

Option 2 is easier, so I vote for that. For now.

Unless you have been able to properly understand the problem across all
platforms. I haven't. For example, Anuj reports the same problem on OSX
Intel, but I don't get the problem on OSX PPC. Perhaps because of
differences between build process and deps?


-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Sat, Dec 19, 2009 at 4:50 PM, Satoshi Asakawa <ashbbb@gmail.com> wrote:

> Hi all,
>
> After remaking the deps files and adding a monkey patch, my local
> Shoes-0.r1279 for Windows works with Mechanize.
>
> Look at a little note:
> http://github.com/ashbb/shoes_hack_note/blob/master/md/hack015.md
>
> Have to improve the structure of deps files and revise the Rakefile to use
> Ruby 1.9 correctly, I think...
>
> But now, anyway it works as a tentative solution. ;-)
>
> ashbb
>
>

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
Satoshi Asakawa
Date:
2010-01-06 @ 16:12
Hi i5m and folks,

I vote 2, too.

I think it's better to try many different ways actively.
At least for now. ;-)

ashbb

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
Satoshi Asakawa
Date:
2009-12-18 @ 18:55
Hi i5m,

> I don't actually think the error is to do with Mechanize.
Yes. I think so too.

> Gets the error "unknown encoding name - US_ASCII
Try to use "US-ASCII" instead of "US_ASCII".

Hope it helps,
ashbb

Re: [shoes] Shoes, Ruby 1.9, Mechanize and Uninitialized constant Encoding::US_ASCII

From:
i5m
Date:
2009-12-17 @ 10:16
ashbb,

I'm not sure why you don't have openssl in your Ruby install. Neither do I
know how to build it in. Note that for Windows, for plain Ruby (non-Shoes)
my preference is to use the new mingw Ruby Installers:

http://rubyinstaller.org/download.html

Although this does require some tweaks to the Rakefile when building shoes,
as outlined here:

http://wiki.github.com/shoes/shoes/buildingshoeswithwindowswdk

I noticed that the rin-shun.com build pete refers to also is missing openssl

-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Wed, Dec 16, 2009 at 5:15 PM, Satoshi Asakawa <ashbbb@gmail.com> wrote:

> Hi i5m,
>
> I'm using this on my Windows XP laptop:
>   - ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-mswin32]
>
> But I got this error. Not using Shoes, just ran one line: require
> 'mechanize' with ruby.
>
> c:/ruby/lib/ruby/1.9.1/net/https.rb:102:in `require': no such file to load
> -- openssl (LoadError)
>
> Umm... will you give me some suggestions?
>
> ashbb
>
>
>
>
>