Files
2026-07-13 13:32:23 +08:00

40 lines
1.2 KiB
Python

# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
import requests
import requests.utils
from django.conf import settings
from rest_framework import status
from rest_framework.exceptions import APIException
from cvat import __version__
_CVAT_USER_AGENT = f"CVAT/{__version__} {requests.utils.default_user_agent()}"
# Note that setting Session.proxies doesn't work correctly if an upstream proxy
# is specified via environment variables: <https://github.com/psf/requests/issues/2018>.
# Therefore, for robust operation, these need to be passed with every request via the
# proxies= parameter.
PROXIES_FOR_UNTRUSTED_URLS = None
if settings.SMOKESCREEN_ENABLED:
PROXIES_FOR_UNTRUSTED_URLS = {
"http": "http://localhost:4750",
"https": "http://localhost:4750",
}
class ResourceIsBusyApiException(APIException):
status_code = status.HTTP_409_CONFLICT
default_detail = (
"This resource is currently busy with another operation. " "Please try again in a moment."
)
default_code = "database_resource_busy"
def make_requests_session() -> requests.Session:
session = requests.Session()
session.headers["User-Agent"] = _CVAT_USER_AGENT
return session