Sometimes, a python script that is making Microsoft Graph requests may be detected by the gateway as a web-crawler if you are using a pool manager and block the request. The error will look similar to this:

{‘error’: {‘code’: ‘UnknownError’, ‘message’: ‘\r\n403 Forbidden\r\n\r\n

403 Forbidden



\r\n\r\n\r\n’, ‘innerError’: {‘date’: ‘{UTC Date/Time}’, ‘request-id’: ‘{guid}’, ‘client-request-id’: ‘{guid}’}}}

To overcome this issue the easiest way is to use the MS Graph SDK for python but if you’re not using that, then you should structure your requests in a similar fashion to the MS Graph SDK for Python which is using a session to make the requests. For example:

from requests import Request, Session

def example_request(url):
    http = Session()
    req = Request('GET', url, headers=h)
    prepped = req.prepare()
    resp = http.send(prepped)
    return resp.json()

Leave a Comment