{"id":8782,"date":"2022-04-20T19:20:08","date_gmt":"2022-04-20T19:20:08","guid":{"rendered":"https:\/\/blogs.aaddevsup.xyz\/?p=8782"},"modified":"2022-04-20T19:20:16","modified_gmt":"2022-04-20T19:20:16","slug":"python-scripts-may-be-detected-as-web-crawler-when-making-microsoft-graph-requests","status":"publish","type":"post","link":"https:\/\/blogs.aaddevsup.xyz\/2022\/04\/python-scripts-may-be-detected-as-web-crawler-when-making-microsoft-graph-requests\/","title":{"rendered":"Python Scripts may be detected as web-crawler when making Microsoft Graph requests."},"content":{"rendered":"\n

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: <\/p>\n\n\n\n

{‘error’: {‘code’: ‘UnknownError’, ‘message’: ‘\\r\\n403 Forbidden\\r\\n\\r\\n<\/p>

403 Forbidden<\/p>

\\r\\n<\/p>

Microsoft-Azure-Application-Gateway\/v2<\/p>

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

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<\/a> which is using a session to make the requests. For example: <\/p>\n\n\n\n

from requests import Request, Session\n\n\ndef example_request(url):\n    http = Session()\n    req = Request('GET', url, headers=h)\n    prepped = req.prepare()\n    resp = http.send(prepped)\n    return resp.json()<\/pre>\n","protected":false},"excerpt":{"rendered":"

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 Microsoft-Azure-Application-Gateway\/v2 \\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…<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,270],"tags":[],"class_list":["post-8782","post","type-post","status-publish","format-standard","hentry","category-microsoftgraph","category-python"],"_links":{"self":[{"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/posts\/8782"}],"collection":[{"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/comments?post=8782"}],"version-history":[{"count":2,"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/posts\/8782\/revisions"}],"predecessor-version":[{"id":8784,"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/posts\/8782\/revisions\/8784"}],"wp:attachment":[{"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/media?parent=8782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/categories?post=8782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.aaddevsup.xyz\/wp-json\/wp\/v2\/tags?post=8782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}