简体   繁体   English

Paypal IPN:UTF-8中的字节序列无效

[英]Paypal IPN: Invalid byte sequence in UTF-8

I have a ruby app that processes paypal payments. 我有一个处理paypal付款的ruby应用程序。 Recently we changed to ruby 2.3.0 and have recently incurred this error: ArgumentError: invalid byte sequence in UTF-8 最近我们更改为ruby 2.3.0并且最近出现了此错误:ArgumentError:UTF-8中的无效字节序列

I've posted the params (cleaned) below and pretty sure it is coming from the Swedish characters and the charset (windows). 我已经发布了下面的params(清理),并且很确定它来自瑞典字符和charset(windows)。

I'm not sure exactly how to fix this, or watch out for it in the future. 我不确定如何解决这个问题,或者在将来注意它。

I'm also not clear on what part of the code the error is occurring. 我也不清楚错误发生在代码的哪一部分。

Help? 救命?

» 30 Mar 2016 10:58:47.729 2016-03-30 17:58:47.428957+00:00 app web.1 - - Started POST "/en/paypal_ipns/cart_purchase_ipn" for 173.0.81.1 at 2016-03-30 17:58:47 +0000
» 30 Mar 2016 10:58:47.731 2016-03-30 17:58:47.435860+00:00 app web.1 - - Processing by PaypalIpnsController#cart_purchase_ipn as HTML
» 30 Mar 2016 10:58:47.731 2016-03-30 17:58:47.435988+00:00 app web.1 - - Parameters: {"mc_gross"=>"10.15", "protection_eligibility"=>"Eligible", "address_status"=>"confirmed", "payer_id"=>"removed", "address_street"=>"Kung\xE4lvsgatan 6 A", "payment_date"=>"08:07:48 Mar 30, 2016 PDT", "payment_status"=>"Completed", "charset"=>"windows-1252", "address_zip"=>"41669", "first_name"=>"Martin", "mc_fee"=>"0.70", "address_country_code"=>"SE", "address_name"=>"Martin removed", "notify_version"=>"3.8", "custom"=>"7173", "payer_status"=>"verified", "business"=>"removed@gmail.com", "address_country"=>"Sweden", "address_city"=>"G\xF6teborg", "quantity"=>"1", "verify_sign"=>"removed", "payer_email"=>"removed@hotmail.com", "txn_id"=>"removed", "payment_type"=>"instant", "last_name"=>"removed", "address_state"=>"", "receiver_email"=>"removed@gmail.com", "payment_fee"=>"0.70", "receiver_id"=>"removed", "txn_type"=>"web_accept", "item_name"=>"removed", "mc_currency"=>"USD", "item_number"=>"13536", "residence_country"=>"SE", "transaction_subject"=>"", "payment_gross"=>"10.15", "ipn_track_id"=>"removed", "locale"=>"en"}
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.446401+00:00 app web.1 - - Cart Load (2.2ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = $1 LIMIT 1 [["id", 13536]]
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.478086+00:00 app web.1 - -
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.478097+00:00 app web.1 - -
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.478098+00:00 app web.1 - - Exception caught, but rendered in pretty page
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.478103+00:00 app web.1 - - #<ArgumentError: invalid byte sequence in UTF-8>
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.478272+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:447:in `count'
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.478274+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:447:in `binary?'
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.478275+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:316:in `visit_String'
» 30 Mar 2016 10:58:47.738 2016-03-30 17:58:47.478275+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
» 30 Mar 2016 10:58:47.743 2016-03-30 17:58:47.478276+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:493:in `block in visit_hash_subclass'
» 30 Mar 2016 10:58:47.743 2016-03-30 17:58:47.478278+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.5.1/lib/action_controller/metal/strong_parameters.rb:185:in `each_pair'
» 30 Mar 2016 10:58:47.743 2016-03-30 17:58:47.478278+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.5.1/lib/action_controller/metal/strong_parameters.rb:185:in `each_pair'
» 30 Mar 2016 10:58:47.743 2016-03-30 17:58:47.478279+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:491:in `visit_hash_subclass'
» 30 Mar 2016 10:58:47.743 2016-03-30 17:58:47.478280+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:389:in `visit_Hash'
» 30 Mar 2016 10:58:47.743 2016-03-30 17:58:47.478280+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:163:in `accept'
» 30 Mar 2016 10:58:47.743 2016-03-30 17:58:47.478281+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych/visitors/yaml_tree.rb:127:in `push'
» 30 Mar 2016 10:58:47.748 2016-03-30 17:58:47.478282+00:00 app web.1 - - /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:416:in `dump'
» 30 Mar 2016 10:58:47.748 2016-03-30 17:58:47.478283+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/coders/yaml_column.rb:20:in `dump'
» 30 Mar 2016 10:58:47.748 2016-03-30 17:58:47.478283+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/type/serialized.rb:26:in `type_cast_for_database'
» 30 Mar 2016 10:58:47.748 2016-03-30 17:58:47.478284+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/type/mutable.rb:5:in `type_cast_from_user'
» 30 Mar 2016 10:58:47.748 2016-03-30 17:58:47.478285+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute.rb:110:in `type_cast'
» 30 Mar 2016 10:58:47.748 2016-03-30 17:58:47.478286+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute.rb:42:in `original_value'
» 30 Mar 2016 10:58:47.748 2016-03-30 17:58:47.478286+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute.rb:37:in `value'
» 30 Mar 2016 10:58:47.752 2016-03-30 17:58:47.478287+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute.rb:50:in `changed_from?'
» 30 Mar 2016 10:58:47.752 2016-03-30 17:58:47.478288+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/dirty.rb:142:in `_field_changed?'
» 30 Mar 2016 10:58:47.752 2016-03-30 17:58:47.478289+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/dirty.rb:115:in `save_changed_attribute'
» 30 Mar 2016 10:58:47.752 2016-03-30 17:58:47.478289+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/dirty.rb:98:in `write_attribute'
» 30 Mar 2016 10:58:47.752 2016-03-30 17:58:47.478290+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods.rb:50:in `__temp__07162716d637'
» 30 Mar 2016 10:58:47.752 2016-03-30 17:58:47.478291+00:00 app web.1 - - /app/app/models/paypal_ipn.rb:20:in `params_info='
» 30 Mar 2016 10:58:47.752 2016-03-30 17:58:47.478291+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:54:in `public_send'
» 30 Mar 2016 10:58:47.762 2016-03-30 17:58:47.478292+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
» 30 Mar 2016 10:58:47.762 2016-03-30 17:58:47.478293+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:65:in `block in assign_nested_parameter_attributes'
» 30 Mar 2016 10:58:47.762 2016-03-30 17:58:47.478293+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:65:in `each'
» 30 Mar 2016 10:58:47.762 2016-03-30 17:58:47.478294+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:65:in `assign_nested_parameter_attributes'
» 30 Mar 2016 10:58:47.762 2016-03-30 17:58:47.478295+00:00 app web.1 - - /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.5.1/lib/active_record/attribute_assignment.rb:45:in `assign_attributes'
» 30 Mar 2016 10:58:47.762 2016-03-30 17:58:47.485285+00:00 app web.1 - - Rendered main/message.html.haml within layouts/application (1.4ms)

You have strings in there with extended ascii, and they're being interpreted as UTF-8. 你有扩展的ascii字符串,它们被解释为UTF-8。 You need to force change their encoding to something supporting those high bytes, "ISO-8859-1" would be my recommendation, and then convert to UTF-8 after that: 您需要强制将其编码更改为支持那些高字节的内容,“ISO-8859-1”将是我的建议,然后转换为UTF-8:

str.force_encoding("ISO-8859-1").encode("UTF-8")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM