Skip to content

404 error when uploading/inserting a video via youtube/v3 #1036

@idlechara

Description

@idlechara

Environment details

  • OS type and version: Pop!_OS 20.04 LTS - 5.4.0-7642-generic x86_64 GNU/Linux
  • Python version: python 3.8.5
  • pip version: pip 20.2.2
  • google-api-python-client version: 1.12.1

Steps to reproduce

  1. Authenticate
  2. Upload a video using youtube data API

Result

Intent to upload a file results into a 404 error, which it seems related to the endpoint availability. But according to the docs, the endpoint is the correct one (https://developers.google.com/youtube/v3/docs/videos/insert).

Expected outcome

Any other error but 404 😢

Code example

from google_auth_oauthlib.flow import InstalledAppFlow
import httplib2
httplib2.debuglevel = 4
from apiclient.http import MediaFileUpload
from googleapiclient.discovery import build

flow = InstalledAppFlow.from_client_secrets_file(
    'client_secret.json',
    scopes= ["https://www.googleapis.com/auth/youtube.upload",
          "https://www.googleapis.com/auth/youtube.force-ssl",
          "https://www.googleapis.com/auth/youtube",
          "https://www.googleapis.com/auth/youtubepartner",
          "https://www.googleapis.com/auth/youtube.readonly"] )

flow.run_local_server()

credentials = flow.credentials
service = build('youtube', 'v3', credentials=credentials)
video_service = service.videos()


body = {
    "snippet" : {
        "title": "I can't upload this UwU",
        "description": "some description"
    },
    "status" : {
        "privacyStatus": "private"
    }
}

FILE = "./output.mp4"
# Call the API's videos.insert method to create and upload the video.
insert_request = video_service.insert(
    part=",".join(body.keys()),
    body=body,
    media_body=MediaFileUpload(FILE, mimetype='application/octet-stream', resumable=True)
)

try:
    insert_request.execute()
except Exception as e:
    print(e)
    error = e

Stack trace

---------------------------------------------------------------------------
ResumableUploadError                      Traceback (most recent call last)
 in 
     18 
     19 # try:
---> 20 insert_request.execute()
     21 # except Exception as e:
     22 #     print(e)

~/.anaconda3/envs/workflows/lib/python3.8/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

~/.anaconda3/envs/workflows/lib/python3.8/site-packages/googleapiclient/http.py in execute(self, http, num_retries)
    869             body = None
    870             while body is None:
--> 871                 _, body = self.next_chunk(http=http, num_retries=num_retries)
    872             return body
    873 

~/.anaconda3/envs/workflows/lib/python3.8/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

~/.anaconda3/envs/workflows/lib/python3.8/site-packages/googleapiclient/http.py in next_chunk(self, http, num_retries)
    989                 self.resumable_uri = resp["location"]
    990             else:
--> 991                 raise ResumableUploadError(resp, content)
    992         elif self._in_error_state:
    993             # If we are in an error state then query the server for current state of

ResumableUploadError: 

http2lib debug

send: b'POST /upload/youtube/v3/videos?part=snippet%2Cstatus&alt=json&uploadType=resumable HTTP/1.1\r\nHost: youtube.googleapis.com\r\naccept: application/json\r\naccept-encoding: gzip, deflate\r\nuser-agent: (gzip)\r\nx-goog-api-client: gdcl/1.12.1 gl-python/3.8.5\r\ncontent-type: application/json\r\nx-upload-content-type: application/octet-stream\r\nx-upload-content-length: 9926861\r\ncontent-length: 124\r\nauthorization: Bearer haha-secret-haha-tokenbearer\r\n\r\n'
send: b'{"snippet": {"title": "I can\'t upload this UwU", "description": "some description"}, "status": {"privacyStatus": "private"}}'
reply: ''
connect: (youtube.googleapis.com, 443)
send: b'POST /upload/youtube/v3/videos?part=snippet%2Cstatus&alt=json&uploadType=resumable HTTP/1.1\r\nHost: youtube.googleapis.com\r\naccept: application/json\r\naccept-encoding: gzip, deflate\r\nuser-agent: (gzip)\r\nx-goog-api-client: gdcl/1.12.1 gl-python/3.8.5\r\ncontent-type: application/json\r\nx-upload-content-type: application/octet-stream\r\nx-upload-content-length: 9926861\r\ncontent-length: 124\r\nauthorization: Bearer haha-secret-haha-tokenbearer\r\n\r\n'
send: b'{"snippet": {"title": "I can\'t upload this UwU", "description": "some description"}, "status": {"privacyStatus": "private"}}'
reply: 'HTTP/1.1 404 Not Found\r\n'
header: Content-Type: text/plain; charset=utf-8
header: X-GUploader-UploadID: ABg5-Uyv3fl7EAJrD50rTDGk4xGGxcz9PBQXBIymcGo_coppbbytdnuuXzAWuXyi8t9JKO8ifOuf_n7LID1k2-kkTMSU1ZxkqA
header: Content-Length: 9
header: Date: Fri, 18 Sep 2020 04:40:11 GMT
header: Server: UploadServer
header: Alt-Svc: h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions