I have a Python script that uses the YouTube API to add a video to a playlist that I created. Some of the time the function works, but other times, when I try to execute the request, I get this error message: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'}]">
Why would it work only some of the time and most importantly, is it mine or YouTube's fault? If it is my fault, how can I fix it? Here is the function that I call:
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
I've also printed the video_id to make sure that it is a valid id and it always is. Thanks to anyone who can help :)