The python language is very picky.
Without the code block that surround the line of code that you share it is hard to tell. The best is to share the whole function.
But I would try a few things.
- use double quotes rather than single quotes
- put quotes around $match, in JS you may omit quotes for literal, python is better in this area
Please read Formatting code and log snippets in posts before posting more code or documents.