-
Notifications
You must be signed in to change notification settings - Fork 61
/
api_exceptions.py
312 lines (238 loc) 路 11 KB
/
api_exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
62
63
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
96
97
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#
# Copyright (c) 2019, Neptune Labs Sp. z o.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from neptune import envs
from neptune.exceptions import STYLES, NeptuneException
class NeptuneApiException(NeptuneException):
pass
class NeptuneSSLVerificationError(NeptuneException):
def __init__(self):
message = """
{h1}
----NeptuneSSLVerificationError-----------------------------------------------------------------------
{end}
Neptune client was unable to verify your SSL Certificate.
{bold}What could go wrong?{end}
- You are behind a proxy that inspects traffic to Neptune servers.
- Contact your network administrator
- Your on-prem installation's SSL/TLS certificate is not recognized due to a custom Certificate Authority (CA).
- To check run the following command in terminal:
{bash}curl https://<your_domain>/api/backend/echo {end}
- Where <your_domain> is the address that you use to access Neptune UI i.e. abc.com
- Contact your network administrator if you get the following output:
{fail}"curl: (60) server certificate verification failed..."{end}
- Your machine software is not up-to-date.
- Minimal OS requirements:
- Windows >= XP SP3
- macOS >= 10.12.1
- Ubuntu >= 12.04
- Debian >= 8
{bold}What can I do?{end}
You can manually configure Neptune to skip all SSL checks. To do that
set the NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE environment variable to 'TRUE'.
{bold}Note that might mean your connection is less secure{end}.
Linux/Unix
In your terminal run:
{bash}export NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE='TRUE'{end}
Windows
In your terminal run:
{bash}set NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE='TRUE'{end}
Jupyter notebook
In your code cell:
{bash}%env NEPTUNE_ALLOW_SELF_SIGNED_CERTIFICATE='TRUE'{end}
You may also want to check the following docs pages:
- https://docs.neptune.ai/api-reference/environment-variables#neptune_allow_self_signed_certificate
{correct}Need help?{end}-> https://docs.neptune.ai/getting-started/getting-help
"""
super().__init__(message.format(**STYLES))
class ConnectionLost(NeptuneApiException):
def __init__(self):
super(ConnectionLost, self).__init__("Connection lost. Please try again.")
class ServerError(NeptuneApiException):
def __init__(self):
message = """
{h1}
----ServerError-----------------------------------------------------------------------
{end}
Neptune Client Library encountered an unexpected Server Error.
Please try again later or contact Neptune support.
"""
super(ServerError, self).__init__(message.format(**STYLES))
class Unauthorized(NeptuneApiException):
def __init__(self):
message = """
{h1}
----Unauthorized-----------------------------------------------------------------------
{end}
You have no permission to access given resource.
- Verify your API token is correct.
See: https://docs-legacy.neptune.ai/security-and-privacy/api-tokens/how-to-find-and-set-neptune-api-token.html
- Verify if you set your Project qualified name correctly
The correct project qualified name should look like this {correct}WORKSPACE/PROJECT_NAME{end}.
It has two parts:
- {correct}WORKSPACE{end}: which can be your username or your organization name
- {correct}PROJECT_NAME{end}: which is the actual project name you chose
- Ask your organization administrator to grant you necessary privileges to the project
"""
super(Unauthorized, self).__init__(message.format(**STYLES))
class Forbidden(NeptuneApiException):
def __init__(self):
message = """
{h1}
----Forbidden-----------------------------------------------------------------------
{end}
You have no permission to access given resource.
- Verify your API token is correct.
See: https://docs-legacy.neptune.ai/security-and-privacy/api-tokens/how-to-find-and-set-neptune-api-token.html
- Verify if you set your Project qualified name correctly
The correct project qualified name should look like this {correct}WORKSPACE/PROJECT_NAME{end}.
It has two parts:
- {correct}WORKSPACE{end}: which can be your username or your organization name
- {correct}PROJECT_NAME{end}: which is the actual project name you chose
- Ask your organization administrator to grant you necessary privileges to the project
"""
super(Forbidden, self).__init__(message.format(**STYLES))
class InvalidApiKey(NeptuneApiException):
def __init__(self):
message = """
{h1}
----InvalidApiKey-----------------------------------------------------------------------
{end}
Your API token is invalid.
Learn how to get it in this docs page:
https://docs-legacy.neptune.ai/security-and-privacy/api-tokens/how-to-find-and-set-neptune-api-token.html
There are two options to add it:
- specify it in your code
- set an environment variable in your operating system.
{h2}CODE{end}
Pass the token to {bold}neptune.init(){end} via {bold}api_token{end} argument:
{python}neptune.init(project_qualified_name='WORKSPACE_NAME/PROJECT_NAME', api_token='YOUR_API_TOKEN'){end}
{h2}ENVIRONMENT VARIABLE{end} {correct}(Recommended option){end}
or export or set an environment variable depending on your operating system:
{correct}Linux/Unix{end}
In your terminal run:
{bash}export {env_api_token}=YOUR_API_TOKEN{end}
{correct}Windows{end}
In your CMD run:
{bash}set {env_api_token}=YOUR_API_TOKEN{end}
and skip the {bold}api_token{end} argument of {bold}neptune.init(){end}:
{python}neptune.init(project_qualified_name='WORKSPACE_NAME/PROJECT_NAME'){end}
You may also want to check the following docs pages:
- https://docs-legacy.neptune.ai/security-and-privacy/api-tokens/how-to-find-and-set-neptune-api-token.html
- https://docs-legacy.neptune.ai/getting-started/quick-starts/log_first_experiment.html
{correct}Need help?{end}-> https://docs-legacy.neptune.ai/getting-started/getting-help.html
"""
super(InvalidApiKey, self).__init__(
message.format(env_api_token=envs.API_TOKEN_ENV_NAME, **STYLES)
)
class WorkspaceNotFound(NeptuneApiException):
def __init__(self, namespace_name):
message = """
{h1}
----WorkspaceNotFound-------------------------------------------------------------------------
{end}
Workspace {python}{workspace}{end} not found.
Workspace is your username or a name of your team organization.
"""
super(WorkspaceNotFound, self).__init__(message.format(workspace=namespace_name, **STYLES))
class ProjectNotFound(NeptuneApiException):
def __init__(self, project_identifier):
message = """
{h1}
----ProjectNotFound-------------------------------------------------------------------------
{end}
Project {python}{project}{end} not found.
Verify if your project's name was not misspelled. You can find proper name after logging into Neptune UI.
"""
super(ProjectNotFound, self).__init__(message.format(project=project_identifier, **STYLES))
class PathInProjectNotFound(NeptuneApiException):
def __init__(self, path, project_identifier):
super(PathInProjectNotFound, self).__init__(
"Path {} was not found in project {}.".format(path, project_identifier)
)
class PathInExperimentNotFound(NeptuneApiException):
def __init__(self, path, exp_identifier):
super().__init__(f"Path {path} was not found in experiment {exp_identifier}.")
class NotebookNotFound(NeptuneApiException):
def __init__(self, notebook_id, project=None):
if project:
super(NotebookNotFound, self).__init__(
"Notebook '{}' not found in project '{}'.".format(notebook_id, project)
)
else:
super(NotebookNotFound, self).__init__("Notebook '{}' not found.".format(notebook_id))
class ExperimentNotFound(NeptuneApiException):
def __init__(self, experiment_short_id, project_qualified_name):
super(ExperimentNotFound, self).__init__(
"Experiment '{exp}' not found in '{project}'.".format(
exp=experiment_short_id, project=project_qualified_name
)
)
class ChannelNotFound(NeptuneApiException):
def __init__(self, channel_id):
super(ChannelNotFound, self).__init__("Channel '{id}' not found.".format(id=channel_id))
class ExperimentAlreadyFinished(NeptuneApiException):
def __init__(self, experiment_short_id):
super(ExperimentAlreadyFinished, self).__init__(
"Experiment '{}' is already finished.".format(experiment_short_id)
)
class ExperimentLimitReached(NeptuneApiException):
def __init__(self):
super(ExperimentLimitReached, self).__init__("Experiment limit reached.")
class StorageLimitReached(NeptuneApiException):
def __init__(self):
super(StorageLimitReached, self).__init__("Storage limit reached.")
class ExperimentValidationError(NeptuneApiException):
pass
class ChannelAlreadyExists(NeptuneApiException):
def __init__(self, experiment_short_id, channel_name):
super(ChannelAlreadyExists, self).__init__(
"Channel with name '{}' already exists in experiment '{}'.".format(
channel_name, experiment_short_id
)
)
class ChannelDoesNotExist(NeptuneApiException):
def __init__(self, experiment_short_id, channel_name):
super(ChannelDoesNotExist, self).__init__(
"Channel with name '{}' does not exist in experiment '{}'.".format(
channel_name, experiment_short_id
)
)
class ChannelsValuesSendBatchError(NeptuneApiException):
@staticmethod
def _format_error(error):
return "{msg} (metricId: '{channelId}', x: {x})".format(
msg=error.error, channelId=error.channelId, x=error.x
)
def __init__(self, experiment_short_id, batch_errors):
super(ChannelsValuesSendBatchError, self).__init__(
"Received batch errors sending channels' values to experiment {}. "
"Cause: {} "
"Skipping {} values.".format(
experiment_short_id,
self._format_error(batch_errors[0]) if batch_errors else "No errors",
len(batch_errors),
)
)
class ExperimentOperationErrors(NeptuneApiException):
"""Handles minor errors returned by calling `client.executeOperations`"""
def __init__(self, errors):
super().__init__()
self.errors = errors
def __str__(self):
lines = ["Caused by:"]
for error in self.errors:
lines.append(f"\t* {error}")
return "\n".join(lines)