Fix Cloudflare bot detection blocking net_alerter Matrix sends
urllib's default Python-urllib user agent is flagged by Cloudflare Bot Fight Mode (error 1010) when m.example.org homeserver sits behind Cloudflare. Add a browser-like User-Agent to Matrix PUT/POST requests so Cloudflare passes the traffic through.
This commit is contained in:
@@ -103,7 +103,11 @@ def _do_send(token: str, msg: str) -> int:
|
|||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
url,
|
url,
|
||||||
data=payload,
|
data=payload,
|
||||||
headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
|
headers={
|
||||||
|
"Authorization": f"Bearer {token}",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||||
|
},
|
||||||
method="POST",
|
method="POST",
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user