임의의 기준으로 임의의 Http 오류가 발생하면서 Python에서 YouTube API v3으로 미리 정의 된 동영상의 댓글을 얻으려고합니다. 사례 : 파이썬이 오류를 던질 때까지 비디오 ID와 주석 목록이 다운로드됩니다. 만약 내가 프로그램을 다시로드하면 동일하거나 다른 비디오 및 다른 주석에 붙어있을 수 있습니다. 오류 범위는 랜덤 기준으로 40 * 500까지입니다. 시도해보기에 코드를 넣으려고했지만 도움이되지 않았습니다. 마지막으로 스크랩 한 비디오 ID를 기억하고 수동으로 프로그램을 다시로드하는 것 외에는 내가 할 수있는 다른 일이 있습니까? 코드 :Youtube API를 사용하는 동안 임의의 Http 오류가 발생하여 Python을 통해 댓글을 얻으려고합니다.
import httplib2
import urllib2
import os
import sys
import pandas as pd
from apiclient.discovery import build_from_document
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow
DEVELOPER_KEY = "---"
CLIENT_SECRETS_FILE = "client_secrets.json"
YOUTUBE_READ_WRITE_SSL_SCOPE = "https://www.googleapis.com/auth/youtube.force-ssl"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
listL = list()
listL.append("D0uEXoL04OM")
listL.append("eX8-g9wM_Sc")
listL.append("aKInxyP5l7k")
listL.append("vMp__taMQtE")
listL.append("Zd3qcqGKbYA")
listL.append("69sg2o2phVs")
listL.append("QcGhVY3ieu4")
listL.append("t4QhJOFo2S0")
listL.append("NeJPr6ko2Hk")
listL.append("15ka3dFn6LI")
listL.append("hweA36OyxRM")
listL.append("ZmCv5HJJPqQ")
listL.append("zfi5DamYZxA")
listL.append("x7O3GVAqCio")
listL.append("kAbhm5NJTz8")
listL.append("7URzyREVdao")
def comment_threads_list_by_video_id(service, part, video_id):
res = service.commentThreads().list(
part=part,
videoId=video_id,
maxResults="100",
).execute()
nextPageToken = res.get('nextPageToken')
while ('nextPageToken' in res):
nextPage = service.commentThreads().list(
part="snippet",
videoId=video_id,
maxResults="100",
pageToken=nextPageToken
).execute()
res['items'] = res['items'] + nextPage['items']
if 'nextPageToken' not in nextPage:
res.pop('nextPageToken', None)
else:
nextPageToken = nextPage['nextPageToken']
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY)
for item in listL:
try:
print item
comment_threads_list_by_video_id(youtube, 'snippet, replies', item)
except urllib2.HTTPError, err:
print "Http Error happened"
pass
except urllib2.URLError, err:
print "Some other error happened:", err.reason
pass
편집 : -------------------------- 몇몇 오류
HttpError: <HttpError 400 when requesting https://www.googleapis.com/youtube/v3/commentThreads?pageToken=ChYQpqWd6pfYzgIYyISxrpfYzgIgACgcEhQIABDIhLGul9jOAhiQgZuP9IfOAhgCIO4VKJHr35vwuKix-gE%3D&part=snippet&key=AIzaSyBzExhLoWbeHU1iKHZuaYV7IBPJNiyaDkE&alt=json&videoId=D0uEXoL04OM&maxResults=100 returned "The API server failed to successfully process the request. While this can be a transient error, it usually indicates that the requests input is invalid. Check the structure of the <code>commentThread</code> resource in the request body to ensure that it is valid.">
몇 가지 오류 샘플을 관련 오류 텍스트와 함께 게시하십시오. –
v3 API의 초당 요청 수 제한에 도달 할 가능성이 있습니까? – Av4t4r
안녕하세요, 코멘트 주셔서 감사합니다, 지금은 'HTTP 400 오류'무작위로, 나는 전에, 어쩌면 내일 어떤 다른 것 나타납니다 전에 나타납니다. – Darius