Skip to content

Commit 9e28f4a

Browse files
committed
Upgraded SDK V1.10.7 Fix douyin_app_v1.py bugs.
1 parent 166004f commit 9e28f4a

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,25 @@ print(video_data)
145145
- 我们已经使用HTTPX的对大多数端点进行了异步封装,如果你的代码是同步执行的,你可以使用下面的代码防止异步传染。
146146

147147
```python
148-
import asyncio
149-
150148
# 获取抖音单一视频数据 | Get a single video data from Douyin
151149
def fetch_one_video(aweme_id: str):
152-
# 使用asyncio.run防止异步传染到其他代码
153-
# Use asyncio.run to prevent asynchronous infection to other code
154-
return asyncio.run(client.DouyinAppV1.fetch_one_video(aweme_id=aweme_id))
155-
156-
157-
video_data = fetch_one_video(aweme_id="7372484719365098803")
158-
print(video_data)
150+
# 创建一个异步事件循环
151+
# Create an asynchronous event loop
152+
loop = asyncio.get_event_loop()
153+
154+
# 使用异步事件循环运行客户端的fetch_one_video方法,防止异步传染到其他代码。
155+
# Run the client's fetch_one_video method with the asynchronous event loop, preventing asynchronous infection to other code.
156+
try:
157+
__video_data = loop.run_until_complete(client.DouyinAppV1.fetch_one_video(aweme_id=aweme_id))
158+
return __video_data
159+
except Exception as e:
160+
# 如果出现异常,返回异常信息
161+
# If an exception occurs, return the exception information
162+
return str(e)
163+
finally:
164+
# 关闭异步事件循环
165+
# Close the asynchronous event
166+
loop.close()
159167
```
160168

161169
- 由于章节有限,在此处就不列出完整的方法了,你可以通过查看源代码的形式查看每一个属性内实现的方法,并且每个方法接受的参数都已经加上了`type hints`

0 commit comments

Comments
 (0)