Spaces:
Sleeping
Sleeping
ZakharZokhar
commited on
Commit
•
d3af375
1
Parent(s):
f1bf3b9
Update main.py
Browse files
main.py
CHANGED
@@ -1,9 +1,21 @@
|
|
1 |
from fastapi import FastAPI, HTTPException, Body, Request, File, UploadFile, BackgroundTasks
|
2 |
from pydantic import BaseModel
|
|
|
3 |
from fastapi.responses import JSONResponse
|
4 |
from fastapi.templating import Jinja2Templates
|
5 |
import httpx
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
app = FastAPI()
|
8 |
|
9 |
# Определяем модель данных для запроса
|
@@ -14,13 +26,11 @@ class TextRequest(BaseModel):
|
|
14 |
templates = Jinja2Templates(directory="templates")
|
15 |
|
16 |
async def send_post_request(url: str, filename: str):
|
17 |
-
|
18 |
-
print(filename)
|
19 |
try:
|
20 |
async with httpx.AsyncClient() as client:
|
21 |
response = await client.post(url, data={"text": filename})
|
22 |
|
23 |
-
print(response)
|
24 |
# Проверяем статус код ответа
|
25 |
if response.status_code != 200:
|
26 |
raise HTTPException(status_code=response.status_code, detail="Request failed")
|
|
|
1 |
from fastapi import FastAPI, HTTPException, Body, Request, File, UploadFile, BackgroundTasks
|
2 |
from pydantic import BaseModel
|
3 |
+
import logging
|
4 |
from fastapi.responses import JSONResponse
|
5 |
from fastapi.templating import Jinja2Templates
|
6 |
import httpx
|
7 |
|
8 |
+
# Настройка логгера
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
+
logger.setLevel(logging.INFO)
|
11 |
+
|
12 |
+
# Создание обработчика для вывода в консоль
|
13 |
+
console_handler = logging.StreamHandler()
|
14 |
+
console_handler.setLevel(logging.INFO)
|
15 |
+
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
16 |
+
console_handler.setFormatter(formatter)
|
17 |
+
logger.addHandler(console_handler)
|
18 |
+
|
19 |
app = FastAPI()
|
20 |
|
21 |
# Определяем модель данных для запроса
|
|
|
26 |
templates = Jinja2Templates(directory="templates")
|
27 |
|
28 |
async def send_post_request(url: str, filename: str):
|
29 |
+
logger.info(f"POST request must be sent to {url} with filename: {filename}")
|
|
|
30 |
try:
|
31 |
async with httpx.AsyncClient() as client:
|
32 |
response = await client.post(url, data={"text": filename})
|
33 |
|
|
|
34 |
# Проверяем статус код ответа
|
35 |
if response.status_code != 200:
|
36 |
raise HTTPException(status_code=response.status_code, detail="Request failed")
|