ランダムなHttpエラーをランダムに取得しています。ケース:pythonがエラーをスローしてプロセスが停止するまで、ビデオIDとコメントのリストをそれぞれダウンロードします。もし私がプログラムをリロードすると、同じビデオや別のビデオ、そして異なるコメントにぶつかってしまうかもしれません。エラーの範囲は40から500までランダムに設定されます。 試しにコードを入れようとしましたが、助けにはなりませんでした。最後に廃止されたビデオIDを覚えておき、手動でプログラムをリロードする以外は何もできますか? コード:PythonでYouTube API v3を使用してコメントを取得しようとしているときに、Youtube APIを使用してランダムなHttpエラーが発生しました。
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
EDIT:-------------------------- いくつかのエラー
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の1秒あたりのリクエスト数の制限に達している可能性はありますか? – Av4t4r
こんにちは、コメントのおかげで、今私は唯一のランダムな基準で、私は前に取得していない、おそらく明日のいくつかの別のものが表示されます 'HTTP 400エラー'を取得しています。 – Darius