[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Mechanize error, File doesn't exist -- but it DOES!

David Beckwith

9/30/2008 2:43:00 PM

I am using Mechanize to fill out a file upload form for an image file.
My script is telling me that an image file DOESN'T exist:

/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.7.2/lib/www/mechanize/form.rb:273:in
`initialize': No such file or directory -
/Users/dbit/Sites/fuseme/fuseme_rails/app/models/scrapers/web20/web20_logos/evenspacer.gif
(Errno::ENOENT)

Does anybody have a clue as to why it would happen?

When I use the UNIX 'ls' command to ls the file name using the absolute
path name of the image "evenspacer.gif" (as seen in the above error
message), the UNIX prompt lists that file, meaning that it's there!

I thought it might be because the file name was named in a different
character set, but I changed the XML file from which the name of the
file was being taken and retyped in both the XML file and renamed the
file by hand using my keyboard( thereby overwriting whatever character
set it was previously represented in).

Does anybody have any ideas as to what's going on here? I'm a bit
stumped!

Thank you!
David :)
--
Posted via http://www.ruby-....

5 Answers

Mark Thomas

9/30/2008 2:55:00 PM

0

On Sep 30, 10:42 am, David Beckwith <dbitsoluti...@gmail.com> wrote:
> I am using Mechanize to fill out a file upload form for an image file.
> My script is telling me that an image file DOESN'T exist:

Can we see the offending lines of the script? Or do you want wild
guesses?

Have you seen the EXAMPLES file from the docs which has sample upload
code?

-- Mark.

Lex Williams

9/30/2008 3:06:00 PM

0


If you won't post the script , the solution is to step through the code
and see what happens .
--
Posted via http://www.ruby-....

David Beckwith

10/1/2008 8:30:00 AM

0

Here is basically what's running in the script:

file_path = "web20_logos/" + "evenspacer.gif"
puts "rel path: " + file_path
puts "exists?: " + File.exists?( file_path ).to_s
puts "expanded path: " + File.expand_path( file_path )
puts "exists?: " + File.exists?( File.expand_path( file_path )
).to_s

yields:

exists?: false
expanded path:
/Users/dbit/Sites/fuseme/fuseme_rails/app/models/scrapers/web20/web20_logos/evenspacer.gif
exists?: false
/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/form.rb:294:in
`initialize': No such file or directory -
/Users/dbit/Sites/fuseme/fuseme_rails/app/models/scrapers/web20/web20_logos/evenspacer.gif
(Errno::ENOENT)
from
/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/form.rb:294:in
`open'
from
/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/form.rb:294:in
`file_to_multipart'
from
/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/form.rb:200:in
`request_data'
from
/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/form.rb:200:in
`each'
from
/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize/form.rb:200:in
`request_data'
from
/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize.rb:380:in
`post_form'
from
/opt/local/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize.rb:324:in
`submit'
from web20.rb:47:in `submit_new_thing'
from web20.rb:90


But when I type it at the command line:

ruby -e 'puts (File.exist? "web20_logos/evenspacer.gif").to_s'

# It yields true....

Very weird.
--
Posted via http://www.ruby-....

Peter Hickman

10/1/2008 8:42:00 AM

0

One possible source of error might be the user that your rails script is
running as. If your normal user (as you were with the one liner test) is
not the same as the user assigned to run the rails script then it might
be that the rails script / user does not have permission to read the
file or some part of the path (to be sure you could set all files and
directories to a+r and all directories to a+x on the path to the file in
question).

Thats all that I can think of.

David Beckwith

10/1/2008 2:18:00 PM

0

There was a space at the end of the file name in the XML file, but not
in the actual file name . . . . . *sigh*


Peter Hickman wrote:
> One possible source of error might be the user that your rails script is
> running as. If your normal user (as you were with the one liner test) is
> not the same as the user assigned to run the rails script then it might
> be that the rails script / user does not have permission to read the
> file or some part of the path (to be sure you could set all files and
> directories to a+r and all directories to a+x on the path to the file in
> question).
>
> Thats all that I can think of.

--
Posted via http://www.ruby-....