我有一个Python脚本,它使用YouTube API将视频添加到我创建的播放列表中。有些时候函数可以工作,但其他时候,当我尝试执行请求时,我得到以下错误消息:googleapiclient.errors.HttpError: <HttpError 409 when requesting https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet&alt=json returned "The operation was aborted.". Details: "[{'domain': 'youtube.CoreErrorDomain', 'reason': 'SERVICE_UNAVAILABLE'}]">
为什么它只能在某些时候工作,最重要的是,这是我的错还是YouTube的错?如果是我的错,我该如何修复它?下面是我调用的函数:
def addSongToPlaylist(self, video_id, playlist_id): # Adds a song to the playlist given
request = add_video_request=self.youtube_service.playlistItems().insert(
part="snippet",
body={
'snippet': {
playlistId': playlist_id,
'resourceId': {
'kind': 'youtube#video',
'videoId': video_id
}
}
}
)
print(video_id)
response = request.execute()
return response
我还打印了video_id,以确保它是一个有效的id,它总是有效的。感谢任何人谁可以帮助:)
1条答案
按热度按时间xdnvmnnf1#
问题是在youtube sid上,它可能暂时不可用,一个解决方案是放置一个
retry
机制,以便它可以处理这些服务干扰。下面是如何在代码中做到这一点: