英文:
Upgrading Redis on Heroku causing SSL errors in Celery
问题
我最近将我们的Heroku Redis从版本5.0升级到了7.0.11,现在在运行Celery时遇到以下错误:
Traceback (most recent call last):
File "/app/.heroku/python/bin/celery", line 8, in <module>
sys.exit(main())
File "/app/.heroku/python/lib/python3.8/site-packages/celery/__main__.py", line 15, in main
sys.exit(_main())
File "/app/.heroku/python/lib/python3.8/site-packages/celery/bin/celery.py", line 235, in main
return celery(auto_envvar_prefix="CELERY")
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 1055, in main
rv = this.invoke(ctx)
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(this.callback, **ctx.params)
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/celery/bin/base.py", line 134, in caller
return f(ctx, *args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/celery/bin/worker.py", line 348, in worker
worker = app.Worker(
File "/app/.heroku/python/lib/python3.8/site-packages/celery/worker/worker.py", line 98, in __init__
self.setup_instance(**self.prepare_args(**kwargs))
File "/app/.heroku/python/lib/python3.8/site-packages/celery/worker/worker.py", line 119, in setup_instance
self._conninfo = self.app.connection_for_read()
File "/app/.heroku/python/lib/python3.8/site-packages/celery/app/base.py", line 818, in connection_for_read
return self._connection(url or self.conf.broker_read_url, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/celery/app/base.py", line 877, in _connection
return this.amqp.Connection(
File "/app/.heroku/python/lib/python3.8/site-packages/kombu/connection.py", line 203, in __init__
url_params = parse_url(hostname)
File "/app/.heroku/python/lib/python3.8/site-packages/kombu/utils/url.py", line 50, in parse_url
query['ssl'][key] = query[key]
TypeError: 'str' object does not support item assignment
celery.py文件:
from celery import Celery
app = Celery('endpoints')
# namespace='CELERY' means all celery-related configuration keys should have a 'CELERY_' prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.redis_backend_use_ssl = {
'ssl_cert_reqs': 'CERT_NONE'
}
app.conf.broker_use_ssl = {
'ssl_cert_reqs': 'CERT_NONE'
}
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
requirements.txt文件:
dj-database-url==2.0.0
Django==4.2.2
django-environ==0.9.0
django-storages==1.9.1
djangorestframework==3.14.0
django-cors-headers==3.5.0
django-parler==2.3
redis==4.5.5
celery[redis]==5.3.0
在升级之前一切都正常工作,但这个错误导致Celery立即崩溃。
英文:
I've recently upgraded our Heroku Redis from version 5.0 to 7.0.11 and I'm now receiving the following error when running Celery
Traceback (most recent call last):
File "/app/.heroku/python/bin/celery", line 8, in <module>
sys.exit(main())
File "/app/.heroku/python/lib/python3.8/site-packages/celery/__main__.py", line 15, in main
sys.exit(_main())
File "/app/.heroku/python/lib/python3.8/site-packages/celery/bin/celery.py", line 235, in main
return celery(auto_envvar_prefix="CELERY")
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/app/.heroku/python/lib/python3.8/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/celery/bin/base.py", line 134, in caller
return f(ctx, *args, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/celery/bin/worker.py", line 348, in worker
worker = app.Worker(
File "/app/.heroku/python/lib/python3.8/site-packages/celery/worker/worker.py", line 98, in __init__
self.setup_instance(**self.prepare_args(**kwargs))
File "/app/.heroku/python/lib/python3.8/site-packages/celery/worker/worker.py", line 119, in setup_instance
self._conninfo = self.app.connection_for_read()
File "/app/.heroku/python/lib/python3.8/site-packages/celery/app/base.py", line 818, in connection_for_read
return self._connection(url or self.conf.broker_read_url, **kwargs)
File "/app/.heroku/python/lib/python3.8/site-packages/celery/app/base.py", line 877, in _connection
return self.amqp.Connection(
File "/app/.heroku/python/lib/python3.8/site-packages/kombu/connection.py", line 203, in __init__
url_params = parse_url(hostname)
File "/app/.heroku/python/lib/python3.8/site-packages/kombu/utils/url.py", line 50, in parse_url
query['ssl'][key] = query[key]
TypeError: 'str' object does not support item assignment
celery.py
from celery import Celery
app = Celery('endpoints')
# namespace='CELERY' means all celery-related configuration keys should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.redis_backend_use_ssl = {
'ssl_cert_reqs': 'CERT_NONE'
}
app.conf.broker_use_ssl = {
'ssl_cert_reqs': 'CERT_NONE'
}
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
requirements.txt
dj-database-url==2.0.0
Django==4.2.2
django-environ==0.9.0
django-storages==1.9.1
djangorestframework==3.14.0
django-cors-headers==3.5.0
django-parler==2.3
redis==4.5.5
celery[redis]==5.3.0
Everything was working flawlessly prior to the upgrade, but this error is causing celery to crash immediately.
答案1
得分: 0
将此问题的解决方法是将 redis 的要求降级至 4.4.4 并从 celery 的要求中移除 [redis] 附加部分。
英文:
The solution to this issue was to downgrade the redis requirement to 4.4.4 and remove the [redis] extra from the celery requirement.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论