question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
idlecharacommented, Sep 18, 2020

I can confirm that it is working now over here. The API now discovers the correct endpoint googleapis.com instead youtube.googleapis.com.

Screenshot from 2020-09-18 17-49-44

I’m closing this issue as the problem seems unrelated to the library itself and it is already solved.

0reactions
markmac99commented, Sep 18, 2020

Mysteriously working here too now. Maybe an ssl cert expired somewhere in google… 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Youtube v3 playlistItems.insert api returns Video not found ...
Youtube v3 playlistItems.insert api returns Video not found 404 error but video was published in the correct playlist.
Read more >
YouTube Data API - Errors | Google Developers
Check the values of the request's id and videoId parameters to ensure that they are correct. notFound (404), videoNotFound, The video identified ...
Read more >
There Was a Problem with the server (404) Problem Solved
Your browser can't play this video. Learn more. Switch camera. Share. Include ... There Was a Problem with the server ( 404 )...
Read more >
Common uploading errors - YouTube Help - Google Support
If you're having problems uploading your video, select the error message you're seeing and follow the troubleshooting steps to solve your issue.
Read more >
API uploads | BigQuery - Google Cloud
The kind of data that one might want to upload include photos, videos, ... Handle 404 Not Found and 410 Gone errors when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found