python - Django中的YouTube搜索-> manage.py:错误:无法识别的参数:shell

标签 python django youtube oauth-2.0

Youtube Code

如果我在IDLE中使用此代码-一切正常,但是当我在Django项目中使用时,即通过python manage.py shell运行,我会看到下一个:

usage: manage.py [--auth_host_name AUTH_HOST_NAME] [--noauth_local_webserver]
                 [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
                 [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
                 [--max-results MAX_RESULTS]
manage.py: error: unrecognized arguments: shell

我发现该错误发生在以下行:args = argparser.parse_args(),但找不到解决方法。有人可以帮忙吗?

编辑:
启动 shell 程序后,我将调用youtube_search(),但是当解释器执行args = argparser.parse_args()行时, shell 程序将关闭,并且会看到上面的消息。

最佳答案

由于我不需要将任何参数从命令行传递给函数,因此我将其删除:

  argparser.add_argument("--q", help="Search term", default="Google")
  argparser.add_argument("--max-results", help="Max results", default=25)
  args = argparser.parse_args()

并将参数直接传递给函数:
search_queue = 'Jingle Bells'
max_results = 5
youtube_search(search_queue, max_results) 

并在此处进行更改:
def youtube_search(q, max_results):  # old version: def youtube_search(options):
  youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
    developerKey=DEVELOPER_KEY)

  # Call the search.list method to retrieve results matching the specified
  # query term.
  search_response = youtube.search().list(
    q=q,  # old version: q=options.q,
    part="id,snippet",
    maxResults=max_results # old version: maxResults=options.max_results
  ).execute()

关于python - Django中的YouTube搜索-> manage.py:错误:无法识别的参数:shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37579877/

相关文章:

python - 在Python中找出具有一定长度的列表的数量

python - 使用 Azure Key Vault 和 Active Directory 检索 secret

python - Django:WSGIRequest'对象在某些页面上没有属性 'user'?

php - 从 Youtube channel 获取视频链接,从 Urls 中提取视频 ID 并将它们存储在数组中

java - 如何获得YouTube视频API以自动同步视频字幕?

python - 使用多色线向 matplotlib 图添加图例

python - 带有 postgresql 的 SQLAlchemy 产生错误 "Could not locate column in row for column ' attype'"

django - 如何使用 gunicorn 部署 Django + Whitenoise 应用程序?

用于设置 Django 应用程序的 python 路径

youtube - 如何在 tvOS 上播放 YouTube 内容