I've since determined that when using python, I was inadvertently using the url https://graph.microsoft.com/v1.0/me/messages/sendMail, not https://graph.microsoft.com/v1.0/me/sendMail, hence a problem. Long story short, small mistake that I didn't catch at first. Things are working as intended now.
Error 405: 'The OData request is not supported.' when using python requests library. What's going on?
William Drakon
16
Reputation points
POST https://graph.microsoft.com/v1.0/me/sendMail
Content-type: application/json
Request Body:
{
"message": {
"subject": "Subject",
"body": {
"contentType": "HTML",
"content": "<p>Body</p>"
},
"toRecipients": [
{
"emailAddress": {
"address": "email@address.com"
}
}
],
"attachments": [
{
"@odata.type": "#microsoft.graph.fileAttachment",
"name": "filename.pdf",
"contentType": "application/pdf",
"contentBytes": "JVBERi0x..."
}
]
}
}
This 405 error is generated when using the requests library in python:
{'error': {'code': 'ErrorInvalidRequest', 'message': 'The OData request is not supported.'}}
When the identical JSON body is used in the Graph Explorer tool, the response is Accepted - 202.
Identical scopes in either context, the only difference is using requests vs. Graph Explorer. All aspects of the email are correct when sent via Graph Explorer, and other posts/gets have worked when using the requests library. Just not sure what's going on.