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

D

David Beckwith

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 :)
 
M

Mark Thomas

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.
 
L

Lex Williams

If you won't post the script , the solution is to step through the code
and see what happens .
 
D

David Beckwith

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.
 
P

Peter Hickman

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.
 
D

David Beckwith

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top