You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,3 +73,46 @@ for chunk in response:
73
73
print(chunk.choices[0].delta)
74
74
```
75
75
76
+
### 异常处理
77
+
78
+
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `openai.APIConnectionError` is raised.
79
+
80
+
When the API returns a non-success status code (that is, 4xx or 5xx
81
+
response), a subclass of `openai.APIStatusError` is raised, containing `status_code` and `response` properties.
82
+
83
+
All errors inherit from `openai.APIError`.
84
+
85
+
```python
86
+
import openai
87
+
from openai import OpenAI
88
+
89
+
client = OpenAI()
90
+
91
+
try:
92
+
client.fine_tunes.create(
93
+
training_file="file-XGinujblHPwGLSztz8cPS8XY",
94
+
)
95
+
except openai.APIConnectionError as e:
96
+
print("The server could not be reached")
97
+
print(e.__cause__) # an underlying Exception, likely raised within httpx.
98
+
except openai.RateLimitError as e:
99
+
print("A 429 status code was received; we should back off a bit.")
100
+
except openai.APIStatusError as e:
101
+
print("Another non-200-range status code was received")
0 commit comments