Python: handle empty messages properly