我如何从Python脚本作为用户进行验证?
我有一个Python脚本,应该使用链接从Web资源下载数据。碰巧的是,资源是在Active Directory保护的Azure App服务中。我的用户帐户可以访问链接并下载数据(我可以手动从Web浏览器手动执行此操作,但要自动化此过程)。 Python脚本使用请求
库。我无法弄清楚如何正确身份验证,因为当我尝试运行脚本时,我会得到:
Error 403 - Forbidden
The web app you have attempted to reach has blocked your access.
使用请求
不起作用的常规身份验证(使用auth
参数或session.auth
或使用httpntlmauth
)。 我知道可以使用VS代码对Azure进行身份验证,然后使用DefaultazureCrecredential
,但是我无法在哪里使用此defaultazurecrecrecrecrecredential
object(因为它不起作用)使用请求
)。
我不需要整个Python应用程序被注册或以某种方式通过Azure资源识别。这只是下载数据的脚本,不应生产数据。
有什么想法,我如何从Azure中删除数据?
注意:我不是这个Azure应用程序的管理员或创建者,因此无法更改任何限制设置。
简而言之,脚本提出请求的一部分看起来像:
params = {"param1": param1,
"param2": param2}
session = requests.Session()
session.auth = HttpNtlmAuth(USERNAME, PASSWORD)
url = "my-app.azurewebsites.net/the-rest-of-the-path"
response = session.get(url, params=params, verify=False)
I have a Python script that should download data from a web resource using link. It so happened that resource is in Azure App Service protected by Active Directory. My user account is allowed to access the link and download data (I can do it from web browser manually, but want to automate this process). The Python script uses requests
library. I can't figure out how to authenticate properly, cause when I'm trying to run the script, I get:
Error 403 - Forbidden
The web app you have attempted to reach has blocked your access.
Usual authentication with requests
doesn't work (using auth
parameter or session.auth
or with HttpNtlmAuth
).
I know one can use VS Code to authenticate to Azure and then use DefaultAzureCredential
, but I can't get where you should use this DefaultAzureCredential
object (cause it doesn't work with requests
).
I don't need the whole Python app to be registered or somehow else recognizable by Azure resource. It's just a script to download data, that is not supposed to be productionized.
Any ideas how I can scrap the data from Azure?
Note: I'm not an admin or creator of this Azure App, so can't change any restriction settings.
In short, the part of script making request looks like:
params = {"param1": param1,
"param2": param2}
session = requests.Session()
session.auth = HttpNtlmAuth(USERNAME, PASSWORD)
url = "my-app.azurewebsites.net/the-rest-of-the-path"
response = session.get(url, params=params, verify=False)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要访问Azure应用服务,则必须对Azure应用程序服务进行身份验证。如果您无法访问Azure App Service,我们将无法访问Azure资源。
当Web服务器阻止您访问要在浏览器中打开的页面时,您会遇到403禁止错误。大多数时候,您无法做很多事情。但是,有时候问题在您结束时。
这是一些可能导致此错误的点。
这是您可以尝试的可能解决方案:
从Web应用程序的网络页面上删除访问限制。
尝试添加0.0.0.0/0,以访问全部。您以后可以根据自己的需求添加限制。
限制的顺序很重要,因此请仔细检查它。如果您在批准的电话之前有阻塞电话,则可能会产生影响。
您还可以基于X-Forwarded-For的HTTP头标头进行限制。请仔细检查一下。这也可以在代码中发生,具体取决于您处理错误的方式。
“ nofollow noreferrer”>协议支持Azure前门中http头的协议| Microsoft文档
Chech这个,如果您的API在网关后面应用程序网关与服务端点集成
If you want to access the Azure App Service, you have to authenticate the Azure App Service. If you don't have access for Azure App Service, we cannot access the Azure resources.
Genereally, when a web server stops you from accessing the page you're trying to open in your browser, you'll get a 403 Forbidden Error. There isn't much you can do most of the time. However, occasionally the issue is on your end.
Here are some points that can cause this error.
Here are the possible solutions that you can try:
Remove the access restrictions from your web app's Networking page.
Try adding 0.0.0.0/0 to give access to all. You can later add restrictions based on your needs.
The order of the restrictions is important, so double-check it. It may have an impact if you have a blocked call before an approved call.
You can also have restrictions based on http-headers like X-Forwarded-For. Please double-check that. This can also happen in code, depending on how you handle errors.
Protocol support for HTTP headers in Azure Front Door | Microsoft Docs
Chech this, if your API is behind the Gateway Application Gateway integration with service endpoints