Mr-Help commited on
Commit
f07d22f
ยท
verified ยท
1 Parent(s): 7f343d3

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +28 -13
main.py CHANGED
@@ -1,24 +1,45 @@
1
  from fastapi import FastAPI, Response
2
  import requests
 
 
3
 
4
  app = FastAPI()
5
 
6
  @app.get("/get-token")
7
  def get_token():
8
- URL = "https://odoo.binrushd.care/api/auth/token"
9
 
10
  headers = {
11
  "CF-Access-Client-Id": "0491b36d7dcabce5b04f1a53f347bb4e.access",
12
  "CF-Access-Client-Secret": "22152cb41b62393e159daaff7dce433006c3744c5850e6adc15fa3544bb5eb09",
13
  "login": "binrushd.automation@gmail.com",
14
  "password": "BR2025",
15
- "db": "BR_EMR_16.0_202401",
 
 
 
 
 
 
16
  }
17
 
18
  try:
19
  resp = requests.get(URL, headers=headers, timeout=20)
20
 
21
- # ู‡ู†ุง ุจู†ุฑุฌุน ู†ูุณ ูƒูˆุฏ ุงู„ุญุงู„ุฉ ุงู„ู„ูŠ ุฑุฌู‘ุนู‡ ุงู„ุณูŠุฑูุฑ ุงู„ุฃุตู„ูŠ
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  content_type = resp.headers.get("Content-Type", "application/json")
23
  return Response(
24
  content=resp.text,
@@ -27,13 +48,7 @@ def get_token():
27
  )
28
 
29
  except requests.RequestException as e:
30
- # ู„ูˆ ุญุตู„ ุฎุทุฃ ููŠ ุงู„ุงุชุตุงู„ ู†ูุณู‡ ุฃูˆ Timeout
31
- return Response(
32
- content=str(e),
33
- status_code=500,
34
- media_type="text/plain"
35
- )
36
-
37
- @app.get("/ping")
38
- def ping():
39
- return {"status": "alive", "message": "โœ… API is running!"}
 
1
  from fastapi import FastAPI, Response
2
  import requests
3
+ import json
4
+ import sys
5
 
6
  app = FastAPI()
7
 
8
  @app.get("/get-token")
9
  def get_token():
10
+ URL = "https://odoo-demo.binrushd.care/api/auth/token"
11
 
12
  headers = {
13
  "CF-Access-Client-Id": "0491b36d7dcabce5b04f1a53f347bb4e.access",
14
  "CF-Access-Client-Secret": "22152cb41b62393e159daaff7dce433006c3744c5850e6adc15fa3544bb5eb09",
15
  "login": "binrushd.automation@gmail.com",
16
  "password": "BR2025",
17
+ "db": "Live_August_25",
18
+ # ู‡ูŠุฏุฑุฒ ุชู‚ู„ู‘ุฏ ู…ุชุตูุญ
19
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
20
+ "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
21
+ "Accept": "application/json, text/plain, */*",
22
+ "Accept-Language": "en-US,en;q=0.9,ar;q=0.8",
23
+ "Connection": "keep-alive",
24
  }
25
 
26
  try:
27
  resp = requests.get(URL, headers=headers, timeout=20)
28
 
29
+ # ---- Logging ู…ูุตู„ ููŠ ุงู„ุณูŠุฑูุฑ ----
30
+ try:
31
+ body_preview = resp.text[:1000]
32
+ except Exception:
33
+ body_preview = "<unreadable>"
34
+ log_obj = {
35
+ "status_code": resp.status_code,
36
+ "reason": resp.reason,
37
+ "headers": dict(resp.headers),
38
+ "body_preview": body_preview
39
+ }
40
+ print("[ODDO TOKEN RESPONSE]", json.dumps(log_obj, ensure_ascii=False), file=sys.stderr)
41
+
42
+ # ---- ุฑุฌู‘ุน ุงู„ุฑุฏ ูƒู…ุง ู‡ูˆ ุจู†ูุณ ูƒูˆุฏ ุงู„ุญุงู„ุฉ ูˆู†ูˆุน ุงู„ู…ุญุชูˆู‰ ----
43
  content_type = resp.headers.get("Content-Type", "application/json")
44
  return Response(
45
  content=resp.text,
 
48
  )
49
 
50
  except requests.RequestException as e:
51
+ # ุฃุฎุทุงุก ุงู„ุดุจูƒุฉ/timeout
52
+ err_txt = f"Network error: {type(e).__name__} - {str(e)}"
53
+ print("[ODDO TOKEN ERROR]", err_txt, file=sys.stderr)
54
+ return Response(content=err_txt, status_code=502, media_type="text/plain")