import requestsimport jsonurl = 'https://youtube.googleapis.com/youtube/v3/captions?part=snippet&key=XXXXXXXXXX'headers = {'Accept': 'application/json','Authorization': 'Bearer XXXXXXXXXXXXXXXXXXXXXXXXX'}data = {"snippet":{"language":"fr","name":"France","videoId":"TWxxjxSq92E"}}files = {'file': open('subtitles.srt', mode='rb')}response = requests.post(url, headers=headers, data=data, files=files)responseText = json.loads(response._content)print(responseText)
This is giving me this error:
{'error': {'code': 400, 'message': 'The request contains invalid metadata values, which prevent the track from being created. Confirm that the request specifies valid values for the <code>snippet.language</code>, <code>snippet.name</code>, and <code>snippet.videoId</code> properties. The <code>snippet.isDraft</code> property can also be included, but it is not required.', 'errors': [{'message': 'The request contains invalid metadata values, which prevent the track from being created. Confirm that the request specifies valid values for the <code>snippet.language</code>, <code>snippet.name</code>, and <code>snippet.videoId</code> properties. The <code>snippet.isDraft</code> property can also be included, but it is not required.', 'domain': 'youtube.caption', 'reason': 'invalidMetadata', 'location': 'body.snippet', 'locationType': 'other'}]}}
But, everything seems correct, and the documentation on the youtube-v3-api is very poor so I don't know how to fix that. It is giving the same error even by using the cUrl "official" example on the docs.
(I am using the "python version" of the cUrl request and not the python example that we can find in the docs because I want to deploy this code to my own Saas so it is the only way I can do that)
Because there's nobody trying to use this on the internet except me, I tried asking GPT but it didn't really help. On the documentation provided by google it is not even explained how to include a file in the post request for the api.