FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openai-python/openai/error.py at main · lufarapCode/openai-python · GitHub
lufarapCode
/
openai-python
Public
forked from
openai/openai-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openai-python
/
openai
/
error.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
169 lines (135 loc) · 4.17 KB
Breadcrumbs
openai-python
/
openai
/
error.py
Copy path
File metadata and controls
169 lines (135 loc) · 4.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
openai
class
OpenAIError
(
Exception
):
def
__init__
(
self
,
message
=
None
,
http_body
=
None
,
http_status
=
None
,
json_body
=
None
,
headers
=
None
,
code
=
None
,
):
super
(
OpenAIError
,
self
).
__init__
(
message
)
if
http_body
and
hasattr
(
http_body
,
"decode"
):
try
:
http_body
=
http_body
.
decode
(
"utf-8"
)
except
BaseException
:
http_body
=
(
"<Could not decode body as utf-8. "
"Please report to support@openai.com>"
)
self
.
_message
=
message
self
.
http_body
=
http_body
self
.
http_status
=
http_status
self
.
json_body
=
json_body
self
.
headers
=
headers
or
{}
self
.
code
=
code
self
.
request_id
=
self
.
headers
.
get
(
"request-id"
,
None
)
self
.
error
=
self
.
construct_error_object
()
self
.
organization
=
self
.
headers
.
get
(
"openai-organization"
,
None
)
def
__str__
(
self
):
msg
=
self
.
_message
or
"<empty message>"
if
self
.
request_id
is
not
None
:
return
"Request {0}: {1}"
.
format
(
self
.
request_id
,
msg
)
else
:
return
msg
# Returns the underlying `Exception` (base class) message, which is usually
# the raw message returned by OpenAI's API. This was previously available
# in python2 via `error.message`. Unlike `str(error)`, it omits "Request
# req_..." from the beginning of the string.
@
property
def
user_message
(
self
):
return
self
.
_message
def
__repr__
(
self
):
return
"%s(message=%r, http_status=%r, request_id=%r)"
%
(
self
.
__class__
.
__name__
,
self
.
_message
,
self
.
http_status
,
self
.
request_id
,
)
def
construct_error_object
(
self
):
if
(
self
.
json_body
is
None
or
not
isinstance
(
self
.
json_body
,
dict
)
or
"error"
not
in
self
.
json_body
or
not
isinstance
(
self
.
json_body
[
"error"
],
dict
)
):
return
None
return
openai
.
api_resources
.
error_object
.
ErrorObject
.
construct_from
(
self
.
json_body
[
"error"
]
)
class
APIError
(
OpenAIError
):
pass
class
TryAgain
(
OpenAIError
):
pass
class
Timeout
(
OpenAIError
):
pass
class
APIConnectionError
(
OpenAIError
):
def
__init__
(
self
,
message
,
http_body
=
None
,
http_status
=
None
,
json_body
=
None
,
headers
=
None
,
code
=
None
,
should_retry
=
False
,
):
super
(
APIConnectionError
,
self
).
__init__
(
message
,
http_body
,
http_status
,
json_body
,
headers
,
code
)
self
.
should_retry
=
should_retry
class
InvalidRequestError
(
OpenAIError
):
def
__init__
(
self
,
message
,
param
,
code
=
None
,
http_body
=
None
,
http_status
=
None
,
json_body
=
None
,
headers
=
None
,
):
super
(
InvalidRequestError
,
self
).
__init__
(
message
,
http_body
,
http_status
,
json_body
,
headers
,
code
)
self
.
param
=
param
def
__repr__
(
self
):
return
"%s(message=%r, param=%r, code=%r, http_status=%r, "
"request_id=%r)"
%
(
self
.
__class__
.
__name__
,
self
.
_message
,
self
.
param
,
self
.
code
,
self
.
http_status
,
self
.
request_id
,
)
def
__reduce__
(
self
):
return
type
(
self
), (
self
.
_message
,
self
.
param
,
self
.
code
,
self
.
http_body
,
self
.
http_status
,
self
.
json_body
,
self
.
headers
,
)
class
AuthenticationError
(
OpenAIError
):
pass
class
PermissionError
(
OpenAIError
):
pass
class
RateLimitError
(
OpenAIError
):
pass
class
ServiceUnavailableError
(
OpenAIError
):
pass
class
InvalidAPIType
(
OpenAIError
):
pass
class
SignatureVerificationError
(
OpenAIError
):
def
__init__
(
self
,
message
,
sig_header
,
http_body
=
None
):
super
(
SignatureVerificationError
,
self
).
__init__
(
message
,
http_body
)
self
.
sig_header
=
sig_header
def
__reduce__
(
self
):
return
type
(
self
), (
self
.
_message
,
self
.
sig_header
,
self
.
http_body
,
)
Back
|
FazBrowse Home
|
New Git URL