Without this I get the following Python traceback, for an SMS that
contains the UK pound sign.
ERROR:dbus.connection:Exception in handler for D-Bus signal:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 230, in maybe_handle_message
    self._handler(*args, **kwargs)
  File "./receive-sms", line 9, in incoming_message
    print("%s" % (message))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 51: ordinal not in range(128)
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			768 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			768 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/python3
 | 
						|
 | 
						|
from gi.repository import GLib
 | 
						|
 | 
						|
import dbus
 | 
						|
import dbus.mainloop.glib
 | 
						|
 | 
						|
def incoming_message(message, details, path, interface):
 | 
						|
	print("%s" % (message.encode('utf-8')))
 | 
						|
 | 
						|
	for key in details:
 | 
						|
		val = details[key]
 | 
						|
		print("    %s = %s" % (key, val))
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 | 
						|
 | 
						|
	bus = dbus.SystemBus()
 | 
						|
 | 
						|
	bus.add_signal_receiver(incoming_message,
 | 
						|
					bus_name="org.ofono",
 | 
						|
					signal_name = "ImmediateMessage",
 | 
						|
						path_keyword="path",
 | 
						|
						interface_keyword="interface")
 | 
						|
 | 
						|
	bus.add_signal_receiver(incoming_message,
 | 
						|
					bus_name="org.ofono",
 | 
						|
					signal_name = "IncomingMessage",
 | 
						|
						path_keyword="path",
 | 
						|
						interface_keyword="interface")
 | 
						|
 | 
						|
	mainloop = GLib.MainLoop()
 | 
						|
	mainloop.run()
 |