Rails Encoding :: InvalidByteSequenceError(UTF-16上的“<! - ?”) - >

时间:2013-10-07 22:31:32

标签: ruby-on-rails ruby

嗨,如果这是一个简单的问题,我很抱歉,因为我对编程很新。这是一个Ruby on Rails应用程序。我有一个API正在侦听来自我们的供应商的推送通知。当供应商访问API时,我收到此错误:

     ==> log/beta.log <==
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  railties (3.2.13) lib/rails/engine.rb:479:in `call'
  railties (3.2.13) lib/rails/application.rb:223:in `call'
  railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `method_missing'
  passenger (4.0.16) lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
  passenger (4.0.16) lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
  passenger (4.0.16) lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
  passenger (4.0.16) lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'



==> log/passenger.8009.log <==
  /home/pushprod/.rvm/gems/ruby-1.9.3-p392@email_mothership/gems/passenger-4.0.16/helper-scripts/rack-preloader.rb:28:in `<main>'

[ 2013-10-07 20:56:39.4455 25084/7f00f3286700 Pool2/Spawner.h:738 ]: [App 17120 stdout] 
[ 2013-10-07 20:56:54.2027 25084/7f00f3286700 Pool2/SmartSpawner.h:301 ]: Preloader for /usr/local/webapps/email_mothership started on PID 17120, listening on unix:/tmp/passenger.1.0.25079/generation-0/backends/preloader.17120
[ 2013-10-07 20:59:39.6995 25084/7f00f60b7700 Pool2/Spawner.h:738 ]: [App 17919 stdout] 
[ 2013-10-07 20:59:55.1740 25084/7f00f60b7700 Pool2/SmartSpawner.h:301 ]: Preloader for /usr/local/webapps/email_mothership started on PID 17919, listening on unix:/tmp/passenger.1.0.25079/generation-0/backends/preloader.17919
[ 2013-10-07 21:04:39.8805 25084/7f00f60f8700 Pool2/Spawner.h:738 ]: [App 19158 stdout] 
[ 2013-10-07 21:04:54.7856 25084/7f00f60f8700 Pool2/SmartSpawner.h:301 ]: Preloader for /usr/local/webapps/email_mothership started on PID 19158, listening on unix:/tmp/passenger.1.0.25079/generation-0/backends/preloader.19158
[ 2013-10-07 21:19:39.4375 25084/7f00f3286700 Pool2/Spawner.h:738 ]: [App 22742 stdout] 
[ 2013-10-07 21:19:52.9357 25084/7f00f3286700 Pool2/SmartSpawner.h:301 ]: Preloader for /usr/local/webapps/email_mothership started on PID 22742, listening on unix:/tmp/passenger.1.0.25079/generation-0/backends/preloader.22742

==> log/production.log <==
Connecting to database specified by database.yml
Connecting to database specified by database.yml

==> log/passenger.8009.log <==
[ 2013-10-07 22:03:39.3205 25084/7f00f60f8700 Pool2/Spawner.h:738 ]: [App 604 stdout] 

==> log/beta.log <==
Connecting to database specified by database.yml

==> log/passenger.8009.log <==
[ 2013-10-07 22:03:53.3365 25084/7f00f60f8700 Pool2/SmartSpawner.h:301 ]: Preloader for /usr/local/webapps/email_mothership started on PID 604, listening on unix:/tmp/passenger.1.0.25079/generation-0/backends/preloader.604

==> log/beta.log <==
Started POST "/" for 192.XXX.XXX at 2013-10-07 22:03:53 +0000
Error occurred while parsing request parameters.
Contents:



Encoding::InvalidByteSequenceError ("<?" on UTF-16):
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/encoding.rb:41:in `encode'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/encoding.rb:41:in `decode'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/source.rb:58:in `encoding='
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/source.rb:46:in `initialize'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/source.rb:162:in `initialize'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/source.rb:14:in `new'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/source.rb:14:in `create_from'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:127:in `stream='
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:116:in `initialize'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:9:in `new'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:9:in `initialize'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/document.rb:243:in `new'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/document.rb:243:in `build'
  /home/pushprod/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rexml/document.rb:43:in `initialize'
  activesupport (3.2.13) lib/active_support/xml_mini/rexml.rb:30:in `new'
  activesupport (3.2.13) lib/active_support/xml_mini/rexml.rb:30:in `parse'
  activesupport (3.2.13) lib/active_support/xml_mini.rb:80:in `parse'
  activesupport (3.2.13) lib/active_support/core_ext/hash/conversions.rb:98:in `from_xml'
  actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:41:in `parse_formatted_parameters'
  actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:17:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
  rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__4098120160867524569__call__3041131689818678832__callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:143:in `pass'
  rack-cache (1.2) lib/rack/cache/context.rb:155:in `invalidate'
  rack-cache (1.2) lib/rack/cache/context.rb:71:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  railties (3.2.13) lib/rails/engine.rb:479:in `call'
  railties (3.2.13) lib/rails/application.rb:223:in `call'
  railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `method_missing'
  passenger (4.0.16) lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
  passenger (4.0.16) lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
  passenger (4.0.16) lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
  passenger (4.0.16) lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

似乎编码可能是UTF-16而我使用的是UTF-8,但我可能会离开这里。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

将Ruby设置为使用UTF-8

export RUBYOPT=-Ku

答案 1 :(得分:0)

如果Zires的回复不起作用,请尝试

  

string = string.force_encoding(“UTF-8”)