Python 使用django芹菜刮取网站并填充django模型

Python 使用django芹菜刮取网站并填充django模型,python,django,celery,Python,Django,Celery,我很难让芹菜和django一起吃。我想用芹菜刮一个网站,每20分钟更新一些django模型 我在我的应用程序目录中创建了一个具有更新类的任务文件: class Update(PeriodicTask): run_every=datetime.timedelta(minutes=20) def run(self, **kwargs): #update models 如果我从命令行运行该类,该类将正确更新我的modesl: if __name__ == '__ma

我很难让芹菜和django一起吃。我想用芹菜刮一个网站,每20分钟更新一些django模型

我在我的应用程序目录中创建了一个具有更新类的任务文件:

class Update(PeriodicTask):
    run_every=datetime.timedelta(minutes=20)

    def run(self, **kwargs):
        #update models
如果我从命令行运行该类,该类将正确更新我的modesl:

if __name__ == '__main__':
    Update().run()
setting.py中的芹菜配置如下所示:

CELERY_RESULT_BACKEND = "database"
BROKER_HOST = 'localhost'
BROKER_PORT = 5672
BROKER_USER = 'Broker'
BROKER_PASSWORD = '*password*'
BROKER_VHOST = 'broker_vhost'
但是当我运行
manage.py celeryd-v2时,我会收到连接错误:

[2010-12-29 09:28:15,150: ERROR/MainProcess] CarrotListener: Connection Error: [Errno 111] Connection refused. Trying again in 10 seconds...
我错过了什么

更新:

我发现它看起来很不错,因为它使用了我现有的数据库。我已经安装了django kombu和kombu,但现在在运行
manage.py celeryd-v2
时出现以下错误

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "<webapp_path>/lib/python2.6/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "<webapp_path>/lib/python2.6/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "<webapp_path>/lib/python2.6/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "<webapp_path>/lib/python2.6/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "<webapp_path>/lib/python2.6/django_celery-2.1.4-py2.6.egg/djcelery/management/commands/celeryd.py", line 20, in handle
    worker.run(*args, **options)
  File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/bin/celeryd.py", line 83, in run
    from celery.apps.worker import Worker
  File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/apps/worker.py", line 15, in <module>
    from celery.task import discard_all
  File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/task/__init__.py", line 7, in <module>
    from celery.execute import apply_async
  File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/execute/__init__.py", line 7, in <module>
    from celery.result import AsyncResult, EagerResult
  File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/result.py", line 9, in <module>
    from celery.backends import default_backend
  File "<webapp_path>/lib/python2.6/celery-2.1.4-py2.6.egg/celery/backends/__init__.py", line 51, in <module>
    default_backend = DefaultBackend()
TypeError: __init__() takes exactly 2 arguments (1 given)
回溯(最近一次呼叫最后一次):
文件“manage.py”,第11行,在
执行\u管理器(设置)
文件“/lib/python2.6/django/core/management/_init__.py”,第438行,在执行管理器中
utility.execute()
文件“/lib/python2.6/django/core/management/_init__.py”,第379行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/lib/python2.6/django/core/management/base.py”,第191行,从_argv运行
self.execute(*args,**选项._dict__;
文件“/lib/python2.6/django/core/management/base.py”,第220行,在execute中
输出=self.handle(*args,**选项)
文件“/lib/python2.6/django_芹菜-2.1.4-py2.6.egg/djcellery/management/commands/celeryd.py”,第20行,在handle中
worker.run(*args,**选项)
文件“/lib/python2.6/celery-2.1.4-py2.6.egg/celery/bin/celeryd.py”,第83行,运行中
从芹菜.apps.worker导入worker
文件“/lib/python2.6/celery-2.1.4-py2.6.egg/celery/apps/worker.py”,第15行,在
从芹菜。任务导入丢弃所有
文件“/lib/python2.6/cellery-2.1.4-py2.6.egg/cellery/task/_init__.py”,第7行,在
从celery.execute导入应用\u异步
文件“/lib/python2.6/celery-2.1.4-py2.6.egg/celery/execute/_init__.py”,第7行,在
从芹菜中导入AsyncResult,结果
文件“/lib/python2.6/celery-2.1.4-py2.6.egg/celery/result.py”,第9行,在
从celery.backends导入默认\u后端
文件“/lib/python2.6/cellery-2.1.4-py2.6.egg/cellery/backends/_init__.py”,第51行,in
default_backend=DefaultBackend()
TypeError:\uuuu init\uuuuuu()正好接受2个参数(给定1个)

看起来您没有安装/运行代理(RabbitMQ?

我也有同样的问题,问题是导入路径错误

很可能,您将任务导入为

来自芹菜导入任务

而你应该


来自芹菜。任务导入任务

我试着让芹菜尽可能少地使用:)我现在在贫民窟工作。谢谢你把我推到正确的目录。我也遇到同样的错误,也运行GhettoQ。GhettoQ真的是这个贫民区吗?上面写着芹菜-2.1.4-py2.6。你的浆糊里有鸡蛋,但要使用Kombu,你需要芹菜的开发版本(变成2.2)。从git安装:(或pip安装-U;pip安装-U;按该顺序)。