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/