Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,30 +1,23 @@
|
|
| 1 |
# main.py
|
| 2 |
from fastapi import FastAPI, Request, UploadFile
|
| 3 |
from typing import Any, Dict
|
| 4 |
-
import json
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
-
@app.get("/")
|
| 9 |
-
def root():
|
| 10 |
-
return {"ok": True, "msg": "Send POST to /echo"}
|
| 11 |
-
|
| 12 |
-
@app.get("/ping")
|
| 13 |
-
def ping():
|
| 14 |
-
return {"pong": True}
|
| 15 |
-
|
| 16 |
@app.post("/echo")
|
| 17 |
async def echo(request: Request) -> Dict[str, Any]:
|
| 18 |
-
# ุงุทุจุน ุชูุงุตูู ุงูุฑููููุณุช ูู ุงููููุณูู
|
| 19 |
body_bytes = await request.body()
|
| 20 |
-
print("\n" + "="*30 + " NEW REQUEST " + "="*30)
|
| 21 |
-
print("Method:", request.method)
|
| 22 |
-
print("URL:", str(request.url))
|
| 23 |
-
print("Headers:", dict(request.headers))
|
| 24 |
-
print("Raw body (bytes):", body_bytes)
|
| 25 |
-
print("Raw body (str):", body_bytes.decode("utf-8", errors="ignore"))
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
try:
|
| 29 |
parsed = await request.json()
|
| 30 |
except Exception:
|
|
@@ -32,7 +25,6 @@ async def echo(request: Request) -> Dict[str, Any]:
|
|
| 32 |
form = await request.form()
|
| 33 |
parsed = {}
|
| 34 |
for k, v in form.items():
|
| 35 |
-
# ูู ููู ู
ููุงุช
|
| 36 |
if isinstance(v, UploadFile):
|
| 37 |
parsed[k] = {"filename": v.filename, "content_type": v.content_type}
|
| 38 |
else:
|
|
@@ -48,5 +40,3 @@ async def echo(request: Request) -> Dict[str, Any]:
|
|
| 48 |
"headers": dict(request.headers),
|
| 49 |
},
|
| 50 |
}
|
| 51 |
-
|
| 52 |
-
# ููุชุดุบูู ู
ุจุงุดุฑุฉู: uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
|
|
|
| 1 |
# main.py
|
| 2 |
from fastapi import FastAPI, Request, UploadFile
|
| 3 |
from typing import Any, Dict
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
@app.post("/echo")
|
| 8 |
async def echo(request: Request) -> Dict[str, Any]:
|
|
|
|
| 9 |
body_bytes = await request.body()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
print("\n" + "="*30 + " ๐ NEW REQUEST " + "="*30)
|
| 12 |
+
print("๐น Method:", request.method)
|
| 13 |
+
print("๐ URL:", str(request.url))
|
| 14 |
+
print("๐ Headers:", dict(request.headers))
|
| 15 |
+
print("\n๐ฆ Raw body (bytes):")
|
| 16 |
+
print(body_bytes)
|
| 17 |
+
print("\n๐ Raw body (str):")
|
| 18 |
+
print(body_bytes.decode("utf-8", errors="ignore"))
|
| 19 |
+
print("="*75)
|
| 20 |
+
|
| 21 |
try:
|
| 22 |
parsed = await request.json()
|
| 23 |
except Exception:
|
|
|
|
| 25 |
form = await request.form()
|
| 26 |
parsed = {}
|
| 27 |
for k, v in form.items():
|
|
|
|
| 28 |
if isinstance(v, UploadFile):
|
| 29 |
parsed[k] = {"filename": v.filename, "content_type": v.content_type}
|
| 30 |
else:
|
|
|
|
| 40 |
"headers": dict(request.headers),
|
| 41 |
},
|
| 42 |
}
|
|
|
|
|
|