|
| 1 | +--- |
| 2 | +title: Python scripts making Microsoft Graph requests are detected as web crawlers |
| 3 | +description: Provides solutions to an issue where Python Scripts might be detected as web-crawlers when making Microsoft Graph requests. |
| 4 | +ms.date: 04/10/2025 |
| 5 | +ms.service: entra-id |
| 6 | +ms.custom: sap:Problem with using the Graph SDK - libraries |
| 7 | +ms.reviewer: daga, v-weizhu |
| 8 | +--- |
| 9 | +# Python scripts making Microsoft Graph requests are detected as web crawlers |
| 10 | + |
| 11 | +This article provides solutions to an issue where Python Scripts might be detected as web-crawlers when making Microsoft Graph requests. |
| 12 | + |
| 13 | +## Symptoms |
| 14 | + |
| 15 | +A Python script that makes a Microsoft Graph request might sometimes be detected by the gateway as web crawlers. If Python scripts use a pool manager, when you block the request, the following error message is returned: |
| 16 | + |
| 17 | +```output |
| 18 | +{'error': {'code': 'UnknownError', 'message': '\r\n403 Forbidden\r\n\r\n |
| 19 | +
|
| 20 | +403 Forbidden |
| 21 | +
|
| 22 | +\r\n |
| 23 | +
|
| 24 | +Microsoft-Azure-Application-Gateway/v2 |
| 25 | +
|
| 26 | +\r\n\r\n\r\n', 'innerError': {'date': '{UTC Date/Time}', 'request-id': '{guid}', 'client-request-id': '{guid}'}}} |
| 27 | +``` |
| 28 | + |
| 29 | +## Cause |
| 30 | + |
| 31 | +The issue occurs because some Python scripts might not structure their requests in a way that conforms to expected patterns. As a result, the gateway mistakenly identifies the requests as coming from a web-crawler. |
| 32 | + |
| 33 | +## Solution |
| 34 | + |
| 35 | +To resolve this issue, use the [Microsoft Graph SDK for Python](https://github.com/microsoftgraph/msgraph-sdk-python-core). If you don't want to use it, structure your requests similarly to how the SDK handles them by using Python's Session object to send requests. |
| 36 | + |
| 37 | +Here is an example of how you can structure your requests manually: |
| 38 | + |
| 39 | +```python |
| 40 | +from requests import Request, Session |
| 41 | + |
| 42 | +def example\_request(url): |
| 43 | + http = Session() |
| 44 | + req = Request('GET', url, headers=h) |
| 45 | + prepped = req.prepare() |
| 46 | + resp = http.send(prepped) |
| 47 | + return resp.json() |
| 48 | +``` |
| 49 | +[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)] |
0 commit comments