2

I am using gammu-smsd on ubuntu 12.04 as my sms-gateway. It scans information from my modem and inserts it into a postgresql database. Apparently, it tried inserting something into the inbox with invalid characters according to /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 

Now when I try to start the gammu-smsd server:

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

it crashes with the same output in the syslog as I showed above.

What can I do to fix this?

JohnMerlino
  • 425
  • 2
  • 9
  • 20

2 Answers2

3

Postgres already told you what you can do to fix this:

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
"Your client (gammu-smsd in this case) send me gibberish. I don't speak gibberish, I speak 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".
"Tell me what encoding your client is using, either by setting the encoding of the database (which would require dropping & re-creating it), or by having your client set client_encoding appropriately."


If you don't know what encoding gammu-smsd is trying to use, re-create the database with the SQL_ASCII encoding which basically tells Postgres not to care about what you're passing it.
This is a cop-out, but it's a quick solution.

voretaq7
  • 79,345
  • 17
  • 128
  • 213
1

The actual problem here is that gammu-smsd is trying to send UTF-16 to the UTF-8 database:

>>> 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

It should be sending:

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

(see also http://www.fileformat.info/info/unicode/char/1F44D/index.htm)

MikeyB
  • 38,725
  • 10
  • 102
  • 186
  • 1
    It should really be declaring `client_encoding` so Postgres knows what to do with the data (otherwise if I encoded my database as utf-16 the utf-8 data would produce "unexpected results"). – voretaq7 Oct 29 '13 at 17:14
  • Yeah, or that. :) Again, postgres *told you what to fix*. – MikeyB Oct 29 '13 at 20:36