1

Really weird error when running with docker-compose dockerfile:

FROM tiangolo/uvicorn-gunicorn:python3.10-slim

COPY . /app
WORKDIR /app

RUN pip install -r requirements.txt

CMD celery worker -B --app=worker.worker.celery --loglevel=debug

Error:

momo-api-worker-1  | During handling of the above exception, another exception occurred:
momo-api-worker-1  | 
momo-api-worker-1  | Traceback (most recent call last):
momo-api-worker-1  |   File "/usr/local/bin/celery", line 8, in <module>
momo-api-worker-1  |     sys.exit(main())
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/__main__.py", line 16, in main
momo-api-worker-1  |     _main()
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/bin/celery.py", line 322, in main
momo-api-worker-1  |     cmd.execute_from_commandline(argv)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/bin/celery.py", line 499, in execute_from_commandline
momo-api-worker-1  |     super(CeleryCommand, self).execute_from_commandline(argv)))
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/bin/base.py", line 289, in execute_from_commandline
momo-api-worker-1  |     argv = self.setup_app_from_commandline(argv)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/bin/base.py", line 509, in setup_app_from_commandline
momo-api-worker-1  |     self.app = self.find_app(app)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/bin/base.py", line 531, in find_app
momo-api-worker-1  |     return find_app(app, symbol_by_name=self.symbol_by_name)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/app/utils.py", line 373, in find_app
momo-api-worker-1  |     sym = symbol_by_name(app, imp=imp)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/bin/base.py", line 534, in symbol_by_name
momo-api-worker-1  |     return imports.symbol_by_name(name, imp=imp)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/kombu/utils/imports.py", line 59, in symbol_by_name
momo-api-worker-1  |     reraise(ValueError,
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/vine/five.py", line 194, in reraise
momo-api-worker-1  |     raise value.with_traceback(tb)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/kombu/utils/imports.py", line 57, in symbol_by_name
momo-api-worker-1  |     module = imp(module_name, package=package, **kwargs)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/celery/utils/imports.py", line 111, in import_from_cwd
momo-api-worker-1  |     return imp(module, package=package)
momo-api-worker-1  |   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
momo-api-worker-1  |     return _bootstrap._gcd_import(name[level:], package, level)
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
momo-api-flower-1  | [I 230214 17:01:48 mixins:225] Connected to redis://redis:6379/0
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
momo-api-worker-1  |   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
momo-api-worker-1  |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
momo-api-worker-1  |   File "/app/worker/__init__.py", line 1, in <module>
momo-api-worker-1  |     from .worker import celery
momo-api-worker-1  |   File "/app/worker/worker.py", line 5, in <module>
momo-api-worker-1  |     from container import init_container
momo-api-worker-1  |   File "/app/container.py", line 15, in <module>
momo-api-worker-1  |     from services import *
momo-api-worker-1  |   File "/app/services/__init__.py", line 2, in <module>
momo-api-worker-1  |     from .push_notifications import *
momo-api-worker-1  |   File "/app/services/push_notifications.py", line 1, in <module>
momo-api-worker-1  |     from exponent_server_sdk import PushClient, PushMessage
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/exponent_server_sdk/__init__.py", line 4, in <module>
momo-api-worker-1  |     import requests
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/requests/__init__.py", line 147, in <module>
momo-api-worker-1  |     from . import packages, utils
momo-api-worker-1  |   File "/usr/local/lib/python3.10/site-packages/requests/packages.py", line 16, in <module>
momo-api-worker-1  |     locals()[package] = __import__(package)
momo-api-worker-1  | ValueError: Couldn't import 'worker.worker.celery': source code string cannot contain null bytes

But when I run with VS Code no error:

{
            "name": "Worker",
            "type": "python",
            "request": "launch",
            "module": "celery",
            "args": [
                "worker",
                "-B",
                "--app=worker.worker.celery",
                "--loglevel=debug"
            ],
            "jinja": true,
            "justMyCode": true
        }
Dirk
  • 3,095
  • 4
  • 19
  • 37
  • Why would you have a NUL in your source in the first place? (Maybe you have it saved as a UTF-16 source file? Don't do that; Microsoft likes UTF-16, but nobody else) – Charles Duffy Feb 14 '23 at 18:04
  • ...you can have NULs _in strings_ in Python, but they should be represented as `'\0'` -- a backslash then a zero, not an actual NUL. – Charles Duffy Feb 14 '23 at 18:05
  • See https://stackoverflow.com/a/56573475/14122 confirming that this can be caused by UTF-16 encoding. – Charles Duffy Feb 14 '23 at 18:06
  • In vs code it says that my project files are all UTF-8. But doesnt the error message say that is it in the `requests` package? – Dirk Feb 20 '23 at 20:25
  • (Hmm, interesting; reading https://github.com/psf/requests/blob/main/requests/packages.py, `requests` goes through the module cache to look for packages where requests itself has an overridden version; but it's only `urllib3` and `idna` it's supposed to be importing; back in an older version that used to be also `chardet`, but not any longer) – Charles Duffy Feb 20 '23 at 20:59
  • Anyhow -- any chance you might have an `idna.py`, `urllib3.py`, or `chardet.py` of your own that's earlier than the standard one in `sys.path`? Can you `import idna`, `import urllib3`, and `import chardet` successfully? – Charles Duffy Feb 20 '23 at 21:00

0 Answers0