加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – PGError:错误:用于编码“UTF8”的无效字节序

发布时间:2020-12-16 23:28:06 所属栏目:百科 来源:网络整理
导读:我从Cloudmailin收集Rails电子邮件时收到以下PGError: PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xbb HINT: This error can also happen if the byte sequence does not match the encoding expected by the server,which is controlle
我从Cloudmailin收集Rails电子邮件时收到以下PGError:
PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xbb HINT: This error can also happen if the byte sequence does not match the encoding expected by the server,which is controlled by "client_encoding". : INSERT INTO "comments" ("content") VALUES ('Reply with blah blah  ????????????????????????????????????????????????????? .....

所以很明显我有一些无效的UTF8字符进入电子邮件吧?所以我试着清理它,但仍有一些东西在偷偷摸摸.这是我到目前为止所拥有的:

message_all_clean = params[:message]
Iconv.conv('UTF-8//IGNORE','UTF-8',message_all_clean)
message_plain_clean = params[:plain]
Iconv.conv('UTF-8//IGNORE',message_plain_clean)

@incoming_mail = IncomingMail.create(:message_all => Base64.encode64(message_all_clean),:message_plain => Base64.encode64(message_plain_clean))

任何想法,想法或建议?谢谢

解决方法

当在Heroku上遇到此问题时,我们转换为US-ASCII以适当地清理传入的数据(即从Word粘贴):
Iconv.conv("UTF-8//IGNORE","US-ASCII",content)

有了这个,我们没有更多的字符编码问题.

另外,请仔细检查是否存在其他需要相同转换的字段,因为它可能会影响将文本块传递到数据库的任何内容.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读