python-o365
python-o365 copied to clipboard
Mailbox Query does not properly escape quote symbols
The above query that contains a ' symbol in the subject filter:
query = mailbox.new_query().on_attribute('subject').contains("who's the best?")
Fails with:
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/users/.../messages?%24top=1&%24filter=contains%28subject%2C+%27who%27s+the+best%3F%27%29 | Error Message: Invalid filter clause: ')' or ',' expected at position 23 in 'contains(subject, 'who's the best?')'.
To properly escape single quotes in ms graph, they must be entered twice ( ' --> '' ):
query = mailbox.new_query().on_attribute('subject').contains("who''s the best?")
I'm unsure if this issue includes other characters that also need to be escaped.
The query object does not escape any characters. But since we use python requests library, the query parameters will be automatically encoded. Except for single quotes and some other characters.
If you need to pass single quotes, you will have to encode them for yourself.