pythonyoutube-apiyoutube-data-api

Error When Uploading Videos via the Youtube Data API v3


I am currently writing an application that involves the uploading of videos to Youtube using the Youtube Data API v3 with Python. This has been working until recently, in which I am suddenly receiving a strange error.

I use the following code to upload videos:

from subprocess import run
command = f'python3 uploadYoutube.py --file="{video_name}" --title="{title}" --description="{vid_des}" --keywords={keywords}" --category="{category}" --privacyStatus="public"'
terminal_output = run(command, capture_output=True).stdout
print(terminal_output)

Where the variables inside the f-string are neither empty nor contain the characters < or >.

This provides the following error:

An HTTP error 400 occurred:\r\nb\'{\\n  "error": {\\n    "code": 400,\\n    "message": "The request metadata specifies an invalid or empty video title.",\\n    "errors": [\\n      {\\n        "message": "The request metadata specifies an invalid or empty video title.",\\n        "domain": "youtube.video",\\n        "reason": "invalidTitle",\\n        "location": "body.snippet.title",\\n        "locationType": "other"\\n      }\\n    ]\\n  }\\n}\\n\'\r\n'

What is the reason for this error?


Solution

  • The request metadata specifies an invalid or empty video title.

    This error message is telling you that either your title is invalid or its not set. You have said in comments that you set it to

    This Video Was Created with AI - Do this yourself for free with the link in the description. #ai #viral

    Which is 103 chars. The maximum length of video titles on YouTube is 100 characters. There for your title is to long and invalid.