【问题标题】:Youtube search in Django -> manage.py: error: unrecognized arguments: shell在 Django 中搜索 Youtube -> manage.py:错误:无法识别的参数:shell
【发布时间】:2016-10-01 11:36:21
【问题描述】:

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 关闭并且我看到上面的消息。

【问题讨论】:

  • 我认为您不是在调用 django manage.py 脚本,而是在调用其他脚本。你应该检查你的路径设置。
  • @ger.s.brett 我激活virtualenv(源/my/path/bin/activate),然后cd 到带有manage.py 的文件夹,然后启动python manage.py shell(我每天做多次,其余的函数\类在这个项目中工作正常:),然后从上面的链接执行youtube search 函数,我看到上面的错误。我做错什么了吗?

标签: python django youtube oauth-2.0


【解决方案1】:

因为我不需要从命令行向函数传递任何参数,所以我只是删除了这个:

  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()

【讨论】:

    猜你喜欢
    • 2020-03-01
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 2016-01-20
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多