test-api / main.py
Mr-Help's picture
Update main.py
fecf142 verified
raw
history blame
1.28 kB
from fastapi import FastAPI, Response
import requests
app = FastAPI()
@app.get("/get-token")
def get_token():
URL = "https://odoo-demo.binrushd.care/api/auth/token"
headers = {
"CF-Access-Client-Id": "0491b36d7dcabce5b04f1a53f347bb4e.access",
"CF-Access-Client-Secret": "22152cb41b62393e159daaff7dce433006c3744c5850e6adc15fa3544bb5eb09",
"login": "binrushd.automation@gmail.com",
"password": "BR2025",
"db": "Live_August_25",
}
try:
resp = requests.get(URL, headers=headers, timeout=20)
# ู‡ู†ุง ุจู†ุฑุฌุน ู†ูุณ ูƒูˆุฏ ุงู„ุญุงู„ุฉ ุงู„ู„ูŠ ุฑุฌู‘ุนู‡ ุงู„ุณูŠุฑูุฑ ุงู„ุฃุตู„ูŠ
content_type = resp.headers.get("Content-Type", "application/json")
return Response(
content=resp.text,
status_code=resp.status_code,
media_type=content_type
)
except requests.RequestException as e:
# ู„ูˆ ุญุตู„ ุฎุทุฃ ููŠ ุงู„ุงุชุตุงู„ ู†ูุณู‡ ุฃูˆ Timeout
return Response(
content=str(e),
status_code=500,
media_type="text/plain"
)
@app.get("/ping")
def ping():
return {"status": "alive", "message": "โœ… API is running!"}