简体   繁体   English

Microsoft Azure 应用程序网关阻止 python 的请求库

[英]Microsoft Azure Application Gateway blocking python's requests library

I'm trying to logon into an API hosted in Azure using Python and requests is my go-to library for http requests.我正在尝试使用 Python 登录到托管在 Azure 中的 API,requests 是我用于 http 请求的首选库。 Tried this:试过这个:

import requests

url = f"https://{SERVER}/{PLATFORM}/Account/Logon"
payload = f'LicenseType=&Password={PASSWORD}&RedirectToMyselfInCaseOfError=false&RememberMe=false&UserName={USERNAME}'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Accept': 'application/json',
}

response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

but got:但得到:

<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>Microsoft-Azure-Application-Gateway/v2</center>
</body>
</html>

if I use another python library such as http.client it will work finely:如果我使用另一个 python 库,例如 http.client,它将正常工作:

import http.client

conn = http.client.HTTPSConnection(SERVER)
payload = f'LicenseType=&Password={PASSWORD}&RedirectToMyselfInCaseOfError=false&RememberMe=false&UserName={USERNAME}'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Accept': 'application/json',
}
conn.request("POST", f"/{PLATFORM}/Account/Logon", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Is there any way to avoid Azure to flag my "requests" lib request as malicious?有什么办法可以避免 Azure 将我的“请求”库请求标记为恶意?

Found the reason: Curl and Python Requests (get) reporting different http status code找到原因: Curl和Python请求(get)报不同的http状态码

Just add a User-Agent field to the headers只需在标题中添加一个 User-Agent 字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试将特定图像上传到 Azure 存储帐户时出现 403 Forbidden - Microsoft-Azure-Application-Gateway/v2 - Getting 403 Forbidden - Microsoft-Azure-Application-Gateway/v2 when trying to upload particular image to the Azure storage account 重写应用程序网关规则 azure - Rewrite rule on application gateway azure 集成 Azure 应用网关、汉德和 Istio - Integrating Azure Application Gateway, AGIC and Istio Azure 应用网关健康检查证书不匹配 - Azure Application gateway health check certificate mismatch 使用 Azure CLI 获取 Azure 应用程序网关的“principalId”值 - Using Azure CLI Get the 'principalId' value of an Azure Application Gateway Azure 事件网格主题的应用程序网关后端池 - Azure Application Gateway backendpool to Event Grid Topic Azure 应用程序网关文件上传限制 - Azure Application Gateway file upload limits python3用chatGPT和AWS API网关发送请求请教问题 - python3 with chatGPT and AWS API gateway to send requests to ask questions Azure 应用程序网关排除 - 检查嵌套请求正文属性 - Azure Application Gateway exclude - inspection of nested request body property Azure 应用程序网关因终端配置而失败 state“失败” - Azure Application gateway fails with terminal provisioning state "Failed"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM