I'm trying to make a search with youtube API search method. It worked a few days, but since yesterday it started showming me a Timeout Error The part of the code:
def YoutubeSearch():
# this is used to build our youtube api
youtube = build('youtube', 'v3', developerKey= 'mykey')
date_tolook = CalculateDate() #Function to calculate the date to look for
request = youtube.search().list(
type = "channel",
part = "snippet",
q = domain_name(ls[15]),
maxResults = 1
)
response = request.execute()
print(response)
duration = CalculateVideoDuration()
if response['pageInfo']['totalResults'] > 0 :
chanid = response['items'][0]['id']['channelId']
request2 = youtube.search().list(
part="snippet",
type = "video",
channelId= chanid,
publishedAfter= date_tolook,
videoDuration=duration,
order = "date"
)
response2 = request2.execute()
print(response2)
if response2['pageInfo']['totalResults'] > 0:
title = response['items'][0]['snippet']['title']
videoid = response['items'][0]['id']['videoId']
request3 = youtube.videos().list(
part="statistics",
id = videoid
)
response3 = request3.execute()
print(response)
numberofviews = response['items'][0]['statistics']['viewCount']
numberoflikes = response['items'][0]['statistics']['likeCount']
SendEmail(ls[15], title, numberofviews, numberoflikes)
CreateCsv(ls[15])
The error:
Traceback (most recent call last):
File "C:\Users\bajan\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "C:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\lib\site-packages\customtkinter\widgets\ctk_button.py", line 372, in clicked
self.command()
File "c:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\main.py", line 70, in doSomething
YoutubeSearch()
File "c:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\main.py", line 119, in YoutubeSearch
response = request.execute()
File "C:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\lib\site-packages\googleapiclient\http.py", line 923, in execute
resp, content = _retry_request(
File "C:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\lib\site-packages\googleapiclient\http.py", line 191, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "C:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\lib\site-packages\httplib2\__init__.py", line 1701, in request
(response, content) = self._request(
File "C:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\lib\site-packages\httplib2\__init__.py", line 1421, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "C:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\lib\site-packages\httplib2\__init__.py", line 1343, in _conn_request
conn.connect()
File "C:\Users\bajan\Desktop\Informatica\Python\YoutubeSearchBot\lib\site-packages\httplib2\__init__.py", line 1133, in connect
sock.connect((self.host, self.port))
Libraries i use:
from sendgrid.helpers.mail import Mail, Email, To, Content
from sendgrid import SendGridAPIClient
from datetime import datetime, timedelta
from googleapiclient.discovery import build
from tkinter.filedialog import askopenfile
import tkinter
import customtkinter
import pandas as pd
import sendgrid
import os
import re
So i thinks it's something about the port or it might be from youtube server? I have tried everything i could find on the internet but i failed. Please help. Thanks!