我正在将 Youtube API v3 与 python 一起使用,在搜索不存在的视频时遇到问题。我正在使用以下代码:
while True:
try:
print "Call Search API..."
youtube = get_authenticated_service()
search_response = youtube.search().list(
part="id,snippet",
maxResults=options.maxResults,
type = "video",
relatedToVideoId = options.q,
videoType="movie"
).execute()
break
except:
print "Failed to connect to API - Retry.."
使用此代码,我正在处理网络不稳定并且需要几秒钟才能重新启动的情况,但是当我定位不存在的视频时,例如 HFpy1nma2E,while 循环将永远运行。有人可以建议我一个更复杂的例外来处理这类问题吗?
提前谢谢你。