Neural Network Model for solving captchas in Python
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

31 lines
1.2KB

  1. from fastapi import FastAPI, HTTPException
  2. from pydantic import BaseModel
  3. from typing import Optional
  4. # Suponha que quebrar_captcha_base64 está definido em outro módulo ou arquivo
  5. from solve_captcha import quebrar_captcha_base64
  6. app = FastAPI()
  7. class CaptchaRequest(BaseModel):
  8. captchafile: str
  9. authtoken: str
  10. @app.post("/solve_captcha{slash_optional:/?}", response_model=dict)
  11. async def solve_captcha(request: CaptchaRequest):
  12. expected_token = "j7MgdTy4LX05RpE1XY0ykLTexu9LuOE4zg5AEMNymL6LAgCUNN8JGjM5wu26FDGV4j0Xz3km8ra51c3ihToa3fj48XpcsWr45g043bLVQA1sTBkJP4j823DNX67mbjqNR8p117sU580153Id0IavORjkCXRP"
  13. if request.authtoken != expected_token:
  14. # Se o token não corresponder, retorne erro 401 Unauthorized
  15. raise HTTPException(status_code=401, detail="Unauthorized")
  16. if not request.captchafile:
  17. raise HTTPException(status_code=400, detail="captchafile is required")
  18. try:
  19. resultado_captcha = quebrar_captcha_base64(request.captchafile)
  20. return {"captcha": "", "text": resultado_captcha, "is_correct": True, "status": 200}
  21. except Exception as e:
  22. raise HTTPException(status_code=500, detail=str(e))