text is supposed to be an empty string here, because pyglet generates a separate event for text (see code below). Can you please revert to empty string and comment/remove out the try-except clause that tries to get the text?