[英]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.