2

So I have a simple test script where I'm trying to upload a 6 second mp4 video to my channel. I've configured everything in google cloud and the authentication is working properly. The problem comes when I run the script. For about 30 seconds nothing is output in the console and then I get this error:

socket.timeout: The write operation timed out

This is my code:

import socket
import datetime
from Google import Create_Service
from googleapiclient.http import MediaFileUpload

CLIENT_SECRET_FILE = 'client_secret.json'
API_NAME = 'youtube'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/youtube.upload']

service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)

upload_date_time = datetime.datetime(
    2021, 12, 25, 12, 30, 0).isoformat() + '.000Z'

request_body = {
    'snippet': {
        'categoryI': 19,
        'title': 'Upload Testing',
        'description': 'Hello World Description',
        'tags': ['Travel', 'video test', 'Travel Tips']
    },
    'status': {
        'privacyStatus': 'private',
        'publishAt': upload_date_time,
        'selfDeclaredMadeForKids': False,
    },
    'notifySubscribers': False
}
    
 mediaFile = MediaFileUpload('HelloWorld.MP4')

 response_upload = service.videos().insert(
     part='snippet,status',
     body=request_body,
     media_body=mediaFile
 ).execute()

Just to note the auth token is generated at Create_Service().

user
  • 1,022
  • 2
  • 8
  • 30

1 Answers1

2

So I was trying to solve this for a bit. All I did was increase the default timeout time for the socket and it works!

import socket
socket.setdefaulttimeout(30000)
user
  • 1,022
  • 2
  • 8
  • 30