I use a python script to search for video information with youtube v3 api. On one computer the script works perfectly, but on another it receive the following error:
File "script.py", line 105, in youtube_search(options) File "script.py", line 16, in youtube_search developerKey = DEVELOPER_KEY ..... File "C:\Python27\lib\httplib.py", line 1013, in getresponse raise ResponseNotReady() httplib.ResponseNotReady.
The youtube_search() function that I'm using is:
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()
Do you have any hints on why I encounter this behavior?
Thanks.