Upgrading Redis on Heroku causing SSL errors in Celery.

huangapple go评论72阅读模式
英文:

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 &quot;/app/.heroku/python/bin/celery&quot;, line 8, in &lt;module&gt;
     sys.exit(main())
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/celery/__main__.py&quot;, line 15, in main
     sys.exit(_main())
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/celery/bin/celery.py&quot;, line 235, in main
     return celery(auto_envvar_prefix=&quot;CELERY&quot;)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/click/core.py&quot;, line 1130, in __call__
     return self.main(*args, **kwargs)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/click/core.py&quot;, line 1055, in main
     rv = self.invoke(ctx)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/click/core.py&quot;, line 1657, in invoke
     return _process_result(sub_ctx.command.invoke(sub_ctx))
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/click/core.py&quot;, line 1404, in invoke
     return ctx.invoke(self.callback, **ctx.params)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/click/core.py&quot;, line 760, in invoke
     return __callback(*args, **kwargs)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/click/decorators.py&quot;, line 26, in new_func
     return f(get_current_context(), *args, **kwargs)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/celery/bin/base.py&quot;, line 134, in caller
     return f(ctx, *args, **kwargs)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/celery/bin/worker.py&quot;, line 348, in worker
     worker = app.Worker(
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/celery/worker/worker.py&quot;, line 98, in __init__
     self.setup_instance(**self.prepare_args(**kwargs))
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/celery/worker/worker.py&quot;, line 119, in setup_instance
     self._conninfo = self.app.connection_for_read()
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/celery/app/base.py&quot;, line 818, in connection_for_read
     return self._connection(url or self.conf.broker_read_url, **kwargs)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/celery/app/base.py&quot;, line 877, in _connection
     return self.amqp.Connection(
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/kombu/connection.py&quot;, line 203, in __init__
     url_params = parse_url(hostname)
   File &quot;/app/.heroku/python/lib/python3.8/site-packages/kombu/utils/url.py&quot;, line 50, in parse_url
     query[&#39;ssl&#39;][key] = query[key]
 TypeError: &#39;str&#39; object does not support item assignment

celery.py

from celery import Celery

app = Celery(&#39;endpoints&#39;)

# namespace=&#39;CELERY&#39; means all celery-related configuration keys should have a `CELERY_` prefix.
app.config_from_object(&#39;django.conf:settings&#39;, namespace=&#39;CELERY&#39;)
app.conf.redis_backend_use_ssl = {
                 &#39;ssl_cert_reqs&#39;: &#39;CERT_NONE&#39;
            }
app.conf.broker_use_ssl = {
                 &#39;ssl_cert_reqs&#39;: &#39;CERT_NONE&#39;
            }

# 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.

huangapple
  • 本文由 发表于 2023年6月22日 04:32:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76526930.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定