我使用 python 脚本通过 youtube v3 api 搜索视频信息。在一台计算机上,脚本运行良好,但在另一台计算机上收到以下错误:
文件“script.py”,第 105 行,在 youtube_search(options) 文件“script.py”,第 16 行,在 youtube_search developerKey = DEVELOPER_KEY ..... 文件“C:\Python27\lib\httplib.py”,行1013,在 getresponse 中引发 ResponseNotReady() httplib.ResponseNotReady。
我正在使用的 youtube_search() 函数是:
def youtube_search(options):
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
developerKey=DEVELOPER_KEY)
search_response = youtube.search().list(
q = options.q,
part = "id, snippet",
maxResults=options.maxResults
).execute()
videos = []
channels = []
playlists = []
videoInfo = []
t = datetime.datetime.now()
ff_name = '[' + options.q + '].txt'
f = open(ff_name, 'w')
no_results = search_response.get("pageInfo")["totalResults"]
page = 1
while (page <= (no_results / 50)):
nextPage = search_response.get("nextPageToken")
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
info = youtube.videos().list(
part = "statistics,contentDetails"
,id = search_result["id"]["videoId"]).execute()
for info_result in info.get("items", []):
videos.append("%s<|>%s<|>%s" % (
time.strftime("%x")
,nextPage
,search_result["snippet"]["title"]
)
f.write(str(videos))
f.write('\n')
videos = []
page = page + 1
search_response = youtube.search().list(
q = options.q,
part = "id,snippet",
maxResults = options.maxResults,
pageToken = nextPage
).execute()
您对我为什么遇到这种行为有任何提示吗?
谢谢。