You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
614 B
Python
29 lines
614 B
Python
# Copyright (C) 2022 CVAT.ai Corporation
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
|
from typing import Optional
|
|
|
|
import requests
|
|
|
|
|
|
def detect_schema(url: str) -> Optional[str]:
|
|
"""
|
|
Attempts to detect URL schema (http or https) if none provided in the URL.
|
|
"""
|
|
|
|
if url.startswith("http://") or url.startswith("https://"):
|
|
return url
|
|
|
|
for schema in ["https://", "http://"]:
|
|
try:
|
|
v = schema + url
|
|
response = requests.request("GET", v)
|
|
response.raise_for_status()
|
|
return v
|
|
except requests.HTTPError:
|
|
pass
|
|
|
|
return None
|