Reference for ultralytics/hub/utils.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/hub/utils.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.hub.utils.request_with_credentials
request_with_credentials(url: str) -> Any
Make an AJAX request with cookies attached in a Google Colab environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL to make the request to. |
required |
Returns:
Type | Description |
---|---|
Any
|
The response data from the AJAX request. |
Raises:
Type | Description |
---|---|
OSError
|
If the function is not run in a Google Colab environment. |
Source code in ultralytics/hub/utils.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
ultralytics.hub.utils.requests_with_progress
requests_with_progress(method: str, url: str, **kwargs)
Make an HTTP request using the specified method and URL, with an optional progress bar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
The HTTP method to use (e.g. 'GET', 'POST'). |
required |
url
|
str
|
The URL to send the request to. |
required |
**kwargs
|
Any
|
Additional keyword arguments to pass to the underlying |
{}
|
Returns:
Type | Description |
---|---|
Response
|
The response object from the HTTP request. |
Notes
- If 'progress' is set to True, the progress bar will display the download progress for responses with a known content length.
- If 'progress' is a number then progress bar will display assuming content length = progress.
Source code in ultralytics/hub/utils.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
ultralytics.hub.utils.smart_request
smart_request(
method: str,
url: str,
retry: int = 3,
timeout: int = 30,
thread: bool = True,
code: int = -1,
verbose: bool = True,
progress: bool = False,
**kwargs
)
Make an HTTP request using the 'requests' library, with exponential backoff retries up to a specified timeout.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
The HTTP method to use for the request. Choices are 'post' and 'get'. |
required |
url
|
str
|
The URL to make the request to. |
required |
retry
|
int
|
Number of retries to attempt before giving up. |
3
|
timeout
|
int
|
Timeout in seconds after which the function will give up retrying. |
30
|
thread
|
bool
|
Whether to execute the request in a separate daemon thread. |
True
|
code
|
int
|
An identifier for the request, used for logging purposes. |
-1
|
verbose
|
bool
|
A flag to determine whether to print out to console or not. |
True
|
progress
|
bool
|
Whether to show a progress bar during the request. |
False
|
**kwargs
|
Any
|
Keyword arguments to be passed to the requests function specified in method. |
{}
|
Returns:
Type | Description |
---|---|
Response | None
|
The HTTP response object. If the request is executed in a separate thread, returns None. |
Source code in ultralytics/hub/utils.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|