if attrs.has_key('message'):

In Python 3, dictionaries changed a lot. Now is easier, change the line above to:

if 'message' in attrs:

Read More...