I'm using the Google API Python client library to run a batch of PlaylistItems: insert calls per the batch method described in the docs. When it's all put together it looks like this:
youtube = get_authenticated_service()batch = youtube.new_batch_http_request(callback=insert_callback)playlistId = "[redacted]"video_ids = [ "d7ypnPjz81I","vZv9-TWdBJM","7uG6E6bVKU0","8EzfBYFU8Q0" ]playlist_items = []for video_id in video_ids: batch.add(youtube.playlistItems().insert( part="snippet", body={"snippet": {"playlistId": playlistId,"resourceId": {"kind": "youtube#video","videoId": video_id } } } ) )response = batch.execute()print(response)def insert_callback(request_id, response, exception): if exception is not None: print(exception) else: print(response)The script loops through the videos and makes an API call to add each one to the playlist, printing the result of the API call to the screen. The outcome of each call is unpredictable. In some cases, the video is successfully added to the playlist and in others, I get the following error response:
<HttpError 500 when requestinghttps://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet&alt=jsonreturned "Internal error encountered.". Details: "[{'message':'Internal error encountered.', 'domain': 'global', 'reason':'backendError'}]">
There is no discernable pattern of success or failure. A video can fail to be added on one run and then succeed on the next.
Is there something I can do to overcome this error? If not, is there any advantage running batches and then retrying the videos that error out until they succeed?