Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Проверка отсутствия ssl-сертификата у сайта #89

Open
ArtemBalandin81 opened this issue Jul 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ArtemBalandin81
Copy link
Owner

ArtemBalandin81 commented Jul 20, 2024

Why?

Как оказалось, модуль requests при отсутствии у сайта сертификата ssl отказывается его открывать.

How Does It Work Now?

У сайта Агидель истек срок ssl-сертификата и приложение перестало его обрабатывать:
www.agidel-am.ru/': 'ConnectionError', 'https://www.ya.ru': 200,

How To Do?

  • в скрипте проверки доступности сайта ничего менять не нужно - т.к. это даже хорошо, что валится подобная ошибка.
  • нужно поправить тестовый урл проверки доступа в Интернет след. образом:
import requests
import structlog
from fastapi import APIRouter, Depends, Query
from requests.exceptions import SSLError

from src.api.constants import *
from src.api.schemas import DBBackupResponse
from src.core.db.user import current_superuser
from src.services.db_backup import DBBackupService
from src.settings import settings

log = structlog.get_logger()
test_router = APIRouter()


@test_router.get(GET_TEST_URL, description=GET_URL_DESCRIPTION)
async def test_get_url(
    url: str = Query(..., example=settings.CONNECTION_TEST_URL_BASE),
) -> dict[str, int | str] | None:
    try:
        status_code = requests.get("https://www.agidel-am.ru/").status_code
        await log.ainfo("{}".format(GET_URL_DESCRIPTION), status_code=status_code, url=url)
        return {url: status_code, "time": ANALYTIC_TO_TIME}
    except SSLError as error:
        await log.aerror("{}".format(FAILED_GET_URL), error=error, url=url)
        return {"error": str(error), "time": ANALYTIC_TO_TIME, "url": url}

Where?

"""src/api/endpoints/test_router.py"""

@ArtemBalandin81 ArtemBalandin81 added the bug Something isn't working label Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant