question

WilliamDrakon-7919 avatar image
1 Vote"
WilliamDrakon-7919 asked WilliamDrakon-7919 answered

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

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-mail
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

WilliamDrakon-7919 avatar image
0 Votes"
WilliamDrakon-7919 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.