Ruby异常:`不兼容的字符编码:ASCII-8BIT和UTF-8`

时间:2014-10-16 06:31:59

标签: ruby-on-rails utf-8 character-encoding ascii protocol-buffers

重要信息在底线!

Rails应用程序在序列化协议缓冲区消息时遇到异常:

  

异常(Encoding :: CompatibilityError):不兼容的字符编码:ASCII-8BIT和UTF-8

==== Stack trace: ====
/usr/local/rvm/gems/ruby-2.0.0-p576/gems/ruby-protocol-buffers-1.5.1/lib/protocol_buffers/runtime/encoder.rb:64:in `write'
/usr/local/rvm/gems/ruby-2.0.0-p576/gems/ruby-protocol-buffers-1.5.1/lib/protocol_buffers/runtime/encoder.rb:64:in `serialize_field_value'
/usr/local/rvm/gems/ruby-2.0.0-p576/gems/ruby-protocol-buffers-1.5.1/lib/protocol_buffers/runtime/encoder.rb:51:in `serialize_field'
/usr/local/rvm/gems/ruby-2.0.0-p576/gems/ruby-protocol-buffers-1.5.1/lib/protocol_buffers/runtime/encoder.rb:38:in `block in encode'
/usr/local/rvm/gems/ruby-2.0.0-p576/gems/ruby-protocol-buffers-1.5.1/lib/protocol_buffers/runtime/encoder.rb:15:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p576/gems/ruby-protocol-buffers-1.5.1/lib/protocol_buffers/runtime/encoder.rb:15:in `encode'
/usr/local/rvm/gems/ruby-2.0.0-p576/gems/ruby-protocol-buffers-1.5.1/lib/protocol_buffers/runtime/message.rb:248:in `serialize'
/usr/local/rvm/gems/ruby-2.0.0-p576/gems/ruby-protocol-buffers-1.5.1/lib/protocol_buffers/runtime/message.rb:255:in `serialize_to_string'
/var/www/html/disp/lib/navs/navs.rb:955:in `compose_message'

第955行是:

[type].pack('N*') + msg.serialize_to_string

其中type是整数,msgProtocolBuffers::Message的后代。

重要信息

我只在任何Web服务器(Apache + Passenger,WEBrick,Puma)中的一台CentOS机器上遇到此异常。在Windows和其他CentOS机器上一切都很好。代码是相同的,每次测试前都会重新创建和播种数据库。

1 个答案:

答案 0 :(得分:0)

通过将Ruby从2.0.0-p576降级到2.0.0-p481来解决

<强>更新

p481不再可供下载。