Mr-Help commited on
Commit
9a8266c
·
verified ·
1 Parent(s): 62f5006

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -2
main.py CHANGED
@@ -45,15 +45,21 @@ def print_human_friendly(payload: Dict[str, Any]) -> None:
45
  print("-"*60 + "\n")
46
 
47
  async def post_to_gas_raw(raw_body: str, content_type: str) -> Tuple[int, str]:
48
- """ يرسل البودي كما هو (RAW) إلى GAS بنفس نوع المحتوى """
49
  if not GAS_WEBAPP_URL or GAS_WEBAPP_URL.startswith("YOUR_"):
50
  return (0, "GAS_WEBAPP_URL is not configured")
 
51
  headers = {"Content-Type": content_type or "application/json"}
52
  timeout = httpx.Timeout(10.0, connect=5.0)
53
- async with httpx.AsyncClient(timeout=timeout) as client:
 
54
  for attempt in range(1, 3):
55
  try:
56
  r = await client.post(GAS_WEBAPP_URL, content=raw_body.encode("utf-8"), headers=headers)
 
 
 
 
 
57
  return (r.status_code, r.text[:5000])
58
  except Exception as e:
59
  if attempt == 2:
 
45
  print("-"*60 + "\n")
46
 
47
  async def post_to_gas_raw(raw_body: str, content_type: str) -> Tuple[int, str]:
 
48
  if not GAS_WEBAPP_URL or GAS_WEBAPP_URL.startswith("YOUR_"):
49
  return (0, "GAS_WEBAPP_URL is not configured")
50
+
51
  headers = {"Content-Type": content_type or "application/json"}
52
  timeout = httpx.Timeout(10.0, connect=5.0)
53
+
54
+ async with httpx.AsyncClient(timeout=timeout, follow_redirects=True) as client:
55
  for attempt in range(1, 3):
56
  try:
57
  r = await client.post(GAS_WEBAPP_URL, content=raw_body.encode("utf-8"), headers=headers)
58
+ # لو كان 302/303 واتبعت التحويل، هيبقى status 200 في الآخر
59
+ # بس لو لسه 302 لأي سبب، اعتبره نجاح وسجّل Location
60
+ if r.status_code in (301, 302, 303, 307, 308):
61
+ loc = r.headers.get("Location", "")
62
+ return (r.status_code, f"Redirected to: {loc}")
63
  return (r.status_code, r.text[:5000])
64
  except Exception as e:
65
  if attempt == 2: