postgresql崩溃与编码错误的gammu-smsd

我在Ubuntu 12.04上使用gammu-smsd作为我的短信网关。 它从我的调制解调器扫描信息并将其插入到postgresql数据库中。 显然,它试图根据/ var / log / syslog插入一些无效字符的收件箱:

Oct 28 16:22:15 porkypig gammu-smsd[14936]: SQL failed: INSERT INTO inbox (ReceivingDateTime, Text, SenderNumber, Coding, SMSCNumber, UDH, Class, TextDecoded, RecipientID) VALUES ('2013-10-24 20:03:19', 'D83DDC4D','+13053057707','Unicode_No_Compression','+14044550007','','-1','<d83d><dc4d>','') Oct 28 16:22:15 porkypig gammu-smsd[14936]: Error: ERROR: invalid byte sequence for encoding "UTF8": 0xeda0bd#012HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding". Oct 28 16:22:15 porkypig gammu-smsd[14936]: Query failed, checking connection 

现在当我尝试启动gammu-smsd服务器时:

 sudo /etc/init.d/gammu-smsd start 

它在系统日志中的崩溃与我上面显示的相同的输出。

我能做些什么来解决这个问题?

Postgres已经告诉过你可以做些什么来解决这个问题:

 Oct 28 16:22:15 porkypig gammu-smsd[14936]: Error: ERROR: invalid byte sequence for encoding "UTF8": 0xeda0bd#012HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding". 

invalid byte sequence for encoding "UTF8": 0xeda0bd#012
“你的客户(在这种情况下是gammu-smsd )给了我乱码,我不会说胡言乱语,我会说utf-8。

This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".
“告诉我你的客户端使用什么编码,或者通过设置数据库的编码(这将需要删除和重新创build),或者让客户端适当地设置client_encoding


如果您不知道gammu-smsd正在尝试使用哪种编码,请使用SQL_ASCII encoding重新创build数据库,这基本上告诉Postgres不要关心您传递的内容。
这是一个警察,但这是一个快速的解决scheme。

这里的实际问题是,gammu-smsd试图将UTF-16发送到UTF-8数据库:

 >>> str = '👍' >>> str '👍' >>> str.encode('utf-16-be') b'\xd8=\xdcM' >>> for c in str.encode('utf-16-be'): print('{:x}'.format(c)) d8 3d dc 4d 

应该发送:

 >>> str.encode('utf-8') b'\xf0\x9f\x91\x8d' 

(另见http://www.fileformat.info/info/unicode/char/1F44D/index.htm