Ruby 1.9 + Net :: FTP =>编码:: UndefinedConversionError [英] Ruby 1.9 + Net::FTP => Encoding::UndefinedConversionError
问题描述
我正在尝试下载一个编码为utf-8的xml文件。如果我使用getbinaryfile,下载工作正常,但我想了解为什么gettextfile不工作。
# - * - 编码:utf-8 - * -
#working
ftp = Net :: FTP.open(host,user,password)
ftp.passive = true
ftp .getbinaryfile(some.xml,tmp / some.xml)
#不工作
ftp = Net :: FTP.open(主机,用户,密码)
ftp.passive = true
#raisees Encoding :: UndefinedConversionError:\xFF从ASCII-8BIT到UTF-8
ftp.gettextfile(some.xml,tmp / some.xml )
我知道如果使用File.open,我可以传递外部和内部编码:
File.open(some.xml,r:ASCI-8BIT:UTF-8)
,但无法为Net :: FTP找到这样的选项。
我还尝试了gettextfile的块版本,但是这并不能正常工作,并提供相同的错误消息。
File.open(some.xml,w:ASCI I-8BIT:UTF-8)do | file |
ftp.gettextfile(some.xml){| line | file.write line}
end
有没有人想到这里有什么问题? p>
使用ftp.getbinaryfile而不是ftp.gettextfile,然后再工作。 :)
i upgraded from Ruby 1.8.7 to 1.9.2 (and Rails 3.2.2) and have the problem that Net::FTP#gettextfile is throwing an Encoding::UndefinedConversionError
I'm trying to download a xml file which is encoded as utf-8. The dowload works fine if i use getbinaryfile, but i would like to understand why gettextfile is not working.
# -*- encoding : utf-8 -*-
# working
ftp = Net::FTP.open(host,user,password)
ftp.passive = true
ftp.getbinaryfile("some.xml","tmp/some.xml")
# not working
ftp = Net::FTP.open(host,user,password)
ftp.passive = true
# raises Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8
ftp.gettextfile("some.xml","tmp/some.xml")
I know that i can pass the external and internal encoding if use File.open like this:
File.open("some.xml", "r:ASCI-8BIT:UTF-8")
but couldn't find an option like this for Net::FTP.
I also tried the block version of gettextfile, but this isn't working as well and gives the same error message.
File.open("some.xml", "w:ASCII-8BIT:UTF-8") do |file|
ftp.gettextfile("some.xml") { |line| file.write line }
end
Has anyone an idea what is wrong here?
Use ftp.getbinaryfile instead of ftp.gettextfile then it works again. :)
这篇关于Ruby 1.9 + Net :: FTP =>编码:: UndefinedConversionError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!