pdf-writer-1.1.8/lib/pdf/writer.rb:712:无效的多字节字符(US-ASCII)

Posted

技术标签:

【中文标题】pdf-writer-1.1.8/lib/pdf/writer.rb:712:无效的多字节字符(US-ASCII)【英文标题】:pdf-writer-1.1.8/lib/pdf/writer.rb:712: invalid multibyte char (US-ASCII) 【发布时间】:2016-09-21 20:46:42 【问题描述】:

我正在使用ruby version 1.9.3 并在启动thin server 时出现错误

    /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.12.4/lib/bundler/runtime.rb:100:in `require': /usr/local/lib/ruby/gems/1.9.1/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:712: invalid multibyte char (US-ASCII) (SyntaxError)
/usr/local/lib/ruby/gems/1.9.1/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:712: invalid multibyte char (US-ASCII)
/usr/local/lib/ruby/gems/1.9.1/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:712: syntax error, unexpected $end, expecting keyword_end
    content = "%PDF-#@version\n%âãÃÓ\n"
                                    ^
    from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.12.4/lib/bundler/runtime.rb:100:in `rescue in block in require'
    from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.12.4/lib/bundler/runtime.rb:77:in `block in require'
    from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.12.4/lib/bundler/runtime.rb:70:in `each'

我从这里得到了解决方案pdf-writer invalid multibyte char (US-ASCII) expecting keyword_end content = "%PDF-#@version\n%âãÏÓ\n" Rails 3

我已将我的gemfile pdf-writer 更改为

gem 'pdf-writer', :git => 'git://github.com/metaskills/pdf-writer.git'

现在,当我运行 bundler 来安装 pdf-writer gem 时,我得到如下 timeout 错误

github.com[0: 192.30.252.123]: errno=Connection timed out
fatal: unable to connect a socket (Connection timed out)
Retrying git clone 'git://github.com/metaskills/pdf-writer.git' "/usr/local/lib/ruby/gems/1.9.1/cache/bundler/git/pdf-writer-ce9b6a7a72845526358421df666643f35691567f" --bare --no-hardlinks --quiet due to error (4/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git://github.com/metaskills/pdf-writer.git' "/usr/local/lib/ruby/gems/1.9.1/cache/bundler/git/pdf-writer-ce9b6a7a72845526358421df666643f35691567f" --bare --no-hardlinks --quiet` in directory /apps/hours_report_3/current has failed.
github.com[0: 192.30.252.123]: errno=Connection timed out
fatal: unable to connect a socket (Connection timed out)
Git error: command `git clone 'git://github.com/metaskills/pdf-writer.git'
"/usr/local/lib/ruby/gems/1.9.1/cache/bundler/git/pdf-writer-ce9b6a7a72845526358421df666643f35691567f" --bare --no-hardlinks --quiet` in directory
/apps/my_dashboard/current has failed.

【问题讨论】:

文件名好像是UTF-8但被解释为ASCII,但是ruby不支持这种方式的ASII,那么你是如何生成内容行的? 我刚刚启动瘦服务器并将其记录在瘦日志中 更改为gem 'pdf-writer', github: 'metaskills/pdf-writer' @МалъСкрылевъ:当我按照上面的建议将其更改为时,我仍然收到超时错误github.com[0: 192.30.252.121]: errno=Connection timed out fatal: unable to connect a socket (Connection timed out) 这是网络错误....尝试多次克隆 git repo 【参考方案1】:

所以这可能是几个不同的问题。对于第一个错误,您可以/usr/local/lib/ruby/gems/1.9.1/gems/pdf-writer-1.1.8/lib/pdf/writer.rb顶部添加显式编码-

# encoding: utf-8

这将侵入一个较旧的库并且充其量是脆弱的,因为您的 Gemfile 不能移植到其他机器上。

对于第二个错误,看起来缓存中的现有 gem 与您尝试安装的远程 gem 之间可能存在冲突,因为它们具有相同的名称。

您可以尝试在本地卸载它以清除缓存-

gem uninstall pdf-writer

然后再次捆绑它-

bundle install

Ruby 1.9.3 在February 2015 中达到了生命的尽头,所以这不是一个理想的情况,但考虑到限制,这应该可以让你继续前进。

【讨论】:

以上是关于pdf-writer-1.1.8/lib/pdf/writer.rb:712:无效的多字节字符(US-ASCII)的主要内容,如果未能解决你的问题,请参考以下文章