Error 405: 'The OData request is not supported.' when using python requests library. What's going on?

William Drakon 16 Reputation points
2021-04-12T15:58:00.28+00:00
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.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,646 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. William Drakon 16 Reputation points
    2021-04-13T13:10:47.193+00:00

    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.

    2 people found this answer helpful.
    0 comments No comments