【发布时间】:2020-11-03 13:18:02
【问题描述】:
尝试使用 Python 删除 YouTube cmets 时出现以下错误。我可以检索和设置 cmets 的审核状态,但不能删除 cmets。想不通。
def deleteComments(service):
request = service.comments().delete(id="Ugzl8ec3rKxt6ClZlSR4AaABAg, 2CUswqQvx9q8MllybCuBF4AaABAg")
request.execute()
错误信息:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/youtube/v3/comments?id=Ugzl8ec3rKxt6ClZlSR4AaABAg%2CUswqQvx9q8MllybCuBF4AaABAg returned "The API server failed to successfully process the request. While this can be a transient error, it usually indicates that the request's input is invalid.">
更新: 以下代码示例批准了一条评论,但在尝试删除另一条评论时生成了一条错误消息。正如@stvar 所建议的,我添加了一个异常来处理错误并在短暂延迟后重试该命令无济于事。不知道还能做什么。
代码示例:
request = service.comments().setModerationStatus(
id="UgyVOfo6iFZPZ-lye9V4AaABAg",
moderationStatus=status
)
request.execute()
print("Approved comment "+"UgyVOfo6iFZPZ-lye9V4AaABAg")
i = 4
while True:
try:
request = service.comments().delete(
id="UgyVOfo6iFZPZ-lye9V4AaABAg"
)
request.execute()
print("Deleted comment "+"UgyVOfo6iFZPZ-lye9V4AaABAg")
break
except:
if (i>8):
break
time.sleep(i)
i=i+2
print("retry after 2 seconds")
输出:
Approved comment Ugys7LJAAAqXjruiM0h4AaABAg
retry after 2 seconds
retry after 2 seconds
retry after 2 seconds
【问题讨论】:
-
尝试了以下方法:
标签: python youtube-api youtube-data-api