基于python脚本的django自定义命令

我正在尝试为 django 创建一个可以运行的自定义命令python manage.py cert_transparency,我已经快完成了,但遇到了一些麻烦。这个的目的是在后台创建一个 24/7 运行的命令,我只是在 docker 容器中运行它。


我收到此错误消息


certificate_update: 0cert [00:00, ?cert/s]Traceback (most recent call last):

  File "manage.py", line 15, in <module>

    execute_from_command_line(sys.argv)

  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line

    utility.execute()

  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv

    self.execute(*args, **cmd_options)

  File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute

    output = self.handle(*args, **options)

  File "/src/scraper/management/commands/cert_transparency.py", line 184, in handle

    certstream.listen_for_events(callback, url=certstream_url)

NameError: name 'callback' is not defined

基本上我想做的只是将此脚本作为 django 中的自定义管理命令导入。

https://img1.sycdn.imooc.com/653884570001476d06380175.jpg

慕娘9325324
浏览 117回答 1
1回答

哆啦的时光机

您定义了该.callback(…)方法两次,所以我认为您应该删除其中之一。.callback(…)您可以使用以下方法传递对该方法的引用self.callback:def&nbsp;handle(self,&nbsp;*args,&nbsp;**options): &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;… &nbsp;&nbsp;&nbsp;&nbsp;certstream.listen_for_events(self.callback,&nbsp;url=certstream_url)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python