我正在按照官方指南以编程方式将视频上传到 YouTube。三周前,当我第一次尝试时,这个方法奏效了,我在浏览器上登录了我的帐户以获取 OAuth2 流程。
现在我的凭据已过期,无法再次上传。这是代码的相关部分,从示例代码复制而来:
def get_authenticated_service():
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE,
scope=YOUTUBE_UPLOAD_SCOPE,
message=MISSING_CLIENT_SECRETS_MESSAGE)
storage = Storage("%s-oauth2.json" % sys.argv[0])
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run_flow(flow, storage, [])
return build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
http=credentials.authorize(httplib2.Http()))
我现在从
oauth2client
: 收到此错误
/usr/local/lib/python3.11/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access upload_youtube.py-oauth2.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Traceback (most recent call last):
File "~/upload_youtube.py", line 291, in <module>
youtube = get_authenticated_service()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "~/upload_youtube.py", line 92, in get_authenticated_service
credentials = run_flow(flow, storage, [])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/oauth2client/tools.py", line 195, in run_flow
logging.getLogger().setLevel(getattr(logging, flags.logging_level))
^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'logging_level'
我卸载并重新安装了
google-api-python-client
和oauth2client
以确保我拥有最新版本,但我仍然遇到相同的错误。
如何解决此错误并获得经过身份验证的 YouTube 服务?
无法访问 upload_youtube.py-oauth2.json:没有这样的文件或目录
Python 报告它无法在指定路径找到该文件,因此您应该为您的凭据设置正确的路径。有时也会发生文件权限配置不正确并且禁止从脚本访问它们的情况。在这种情况下,您需要允许脚本访问该文件