python - 使用 Python 获取 Youtube 数据

标签 python youtube argparse

我正在尝试学习如何分析网络上可用的社交媒体数据,我从 Youtube 开始。

from apiclient.errors import HttpError
from outh2client.tools import argparser
from apiclient.discovery import build
import pandas as pd
DEVELOPER_KEY = "AIzaSyB_F1mCrDydEbGUosnZES-NW-mg1CaOyjI"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
argparser.add_argument("--q", help="Search term", default="apple product")
argparser.add_argument("--max-results", help="Max results", default=50)
args = argparser.parse_args()
options = args

我得到了这个错误。

ArgumentError                             Traceback (most recent call last)
<ipython-input-37-ebbf58549b73> in <module>()
----> 1 argparser.add_argument("--q", help="Search term", default="apple product")
  2 argparser.add_argument("--max-results", help="Max results", default=50)
  3 args = argparser.parse_args()
  4 options = args

/usr/lib/python2.7/argparse.py in add_argument(self, *args, **kwargs)
   1306                 raise ValueError("length of metavar tuple does not match nargs")
   1307 
-> 1308         return self._add_action(action)
   1309 
   1310     def add_argument_group(self, *args, **kwargs):

/usr/lib/python2.7/argparse.py in _add_action(self, action)
   1680     def _add_action(self, action):
   1681         if action.option_strings:
-> 1682             self._optionals._add_action(action)
   1683         else:
   1684             self._positionals._add_action(action)

/usr/lib/python2.7/argparse.py in _add_action(self, action)
   1507 
   1508     def _add_action(self, action):
-> 1509         action = super(_ArgumentGroup, self)._add_action(action)
   1510         self._group_actions.append(action)
   1511         return action
/usr/lib/python2.7/argparse.py in _add_action(self, action)
   1320     def _add_action(self, action):
   1321         # resolve any conflicts
-> 1322         self._check_conflict(action)
   1323 
   1324         # add to actions list

/usr/lib/python2.7/argparse.py in _check_conflict(self, action)
   1458         if confl_optionals:
   1459             conflict_handler = self._get_handler()
-> 1460             conflict_handler(action, confl_optionals)
   1461 
   1462     def _handle_conflict_error(self, action, conflicting_actions):

/usr/lib/python2.7/argparse.py in _handle_conflict_error(self, action, conflicting_actions)
   1465                                      for option_string, action
   1466                                      in conflicting_actions])
-> 1467         raise ArgumentError(action, message % conflict_string)
   1468 
   1469     def _handle_conflict_resolve(self, action, conflicting_actions):

ArgumentError: argument --q: conflicting option string(s): --q

我正在为此使用教程,但出现错误。

最佳答案

看起来像你导入的解析器

from outh2client.tools import argparser

已经定义了一个-q参数。您可以通过查看其代码或执行 argparser.print_help()(在您自己添加任何内容之前)来检查这一点。

因此,最简单的解决方案是为您的论点选择另一个名称。

相关文档是

https://docs.python.org/3.4/library/argparse.html#conflict-handler

通过在该页面上查找“冲突”找到。

https://github.com/google/oauth2client/blob/master/oauth2client/tools.py 上定义的解析器没有 -q 参数。这是你的消息来源吗?我假设缺少的 a 是拼写错误。

关于python - 使用 Python 获取 Youtube 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30818753/

相关文章:

python - 除以包含零的数组,python

javascript - 查询多个Youtube channel

python - 使用 Python3 和 argparse 模块,如果传递了不同的参数,我可以禁止该参数吗?

python - 部分解析后使用 argcomplete

css - 如何确保 iFrame 的纵横比是响应式的?

python - 如何检查特定的子解析器?

python - 如何计算 2D numpy 数组的所有列的总和(有效)

python - ValueError : Expected 2D array, 在拟合模型时得到一维数组

python - 使用 open(),如何判断我是否在文件的最后一行?

angularjs - 嵌入youtube视频会导致CORS错误