Docker-Compose: `name 'basestring' is not defined`
JakobMiksch opened this issue · 6 comments
Describe the bug
Starting GHC with docker-compose fails with error name 'basestring' is not defined
To Reproduce
- Go to
./docker/compose
- run
docker-compose -f docker-compose.yml up
Expected Behavior
GHC should run without errors.
Screenshots or Logfiles
ghc_web | ---> pavement.upgrade
ghc_web | Upgrading database...
ghc_web | cd /GeoHealthCheck/GeoHealthCheck
ghc_web | python manage.py db upgrade
ghc_web | 2021-12-21 09:28:22,156 - init - INFO - created GHC App instance #1
ghc_web | INFO [alembic.runtime.migration] Context impl SQLiteImpl.
ghc_web | INFO [alembic.runtime.migration] Will assume non-transactional DDL.
ghc_web | cd /GeoHealthCheck
ghc_web | Running GHC WSGI on 0.0.0.0:80 with 4 workers and SCRIPT_NAME=
ghc_web | [2021-12-21 09:28:22 +0000] [1] [INFO] Starting gunicorn 20.1.0
ghc_web | [2021-12-21 09:28:22 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
ghc_web | [2021-12-21 09:28:22 +0000] [1] [INFO] Using worker: eventlet
ghc_web | [2021-12-21 09:28:22 +0000] [16] [INFO] Booting worker with pid: 16
ghc_web | [2021-12-21 09:28:22 +0000] [16] [ERROR] Exception in worker process
ghc_web | Traceback (most recent call last):
ghc_web | File "/venv/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
ghc_web | worker.init_process()
ghc_web | File "/venv/lib/python3.7/site-packages/gunicorn/workers/geventlet.py", line 133, in init_process
ghc_web | self.patch()
ghc_web | File "/venv/lib/python3.7/site-packages/gunicorn/workers/geventlet.py", line 124, in patch
ghc_web | eventlet.monkey_patch()
ghc_web | File "/venv/lib/python3.7/site-packages/eventlet/patcher.py", line 296, in monkey_patch
ghc_web | from eventlet.support import psycopg2_patcher
ghc_web | File "/venv/lib/python3.7/site-packages/eventlet/support/psycopg2_patcher.py", line 27, in <module>
ghc_web | import psycopg2
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/__init__.py", line 68, in <module>
ghc_web | from psycopg2 import extensions as _ext
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/extensions.py", line 211, in <module>
ghc_web | from psycopg2. _range import Range # noqa
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 502, in <module>
ghc_web | oid=3904, subtype_oid=23, array_oid=3905)
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 283, in __init__
ghc_web | self._create_ranges(pgrange, pyrange)
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 302, in _create_ranges
ghc_web | if isinstance(pgrange, basestring):
ghc_web | NameError: name 'basestring' is not defined
ghc_web | [2021-12-21 09:28:22 +0000] [16] [INFO] Worker exiting (pid: 16)
ghc_web | [2021-12-21 09:28:22 +0000] [17] [INFO] Booting worker with pid: 17
ghc_web | [2021-12-21 09:28:22 +0000] [17] [ERROR] Exception in worker process
ghc_web | Traceback (most recent call last):
ghc_web | File "/venv/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
ghc_web | worker.init_process()
ghc_web | File "/venv/lib/python3.7/site-packages/gunicorn/workers/geventlet.py", line 133, in init_process
ghc_web | self.patch()
ghc_web | File "/venv/lib/python3.7/site-packages/gunicorn/workers/geventlet.py", line 124, in patch
ghc_web | eventlet.monkey_patch()
ghc_web | File "/venv/lib/python3.7/site-packages/eventlet/patcher.py", line 296, in monkey_patch
ghc_web | from eventlet.support import psycopg2_patcher
ghc_web | File "/venv/lib/python3.7/site-packages/eventlet/support/psycopg2_patcher.py", line 27, in <module>
ghc_web | import psycopg2
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/__init__.py", line 68, in <module>
ghc_web | from psycopg2 import extensions as _ext
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/extensions.py", line 211, in <module>
ghc_web | from psycopg2. _range import Range # noqa
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 502, in <module>
ghc_web | oid=3904, subtype_oid=23, array_oid=3905)
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 283, in __init__
ghc_web | self._create_ranges(pgrange, pyrange)
ghc_web | File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 302, in _create_ranges
ghc_web | if isinstance(pgrange, basestring):
ghc_web | NameError: name 'basestring' is not defined
ghc_web | [2021-12-21 09:28:22 +0000] [17] [INFO] Worker exiting (pid: 17)
ghc_web | [2021-12-21 09:28:22 +0000] [1] [WARNING] Worker with pid 17 was terminated due to signal 15
ghc_web | [2021-12-21 09:28:22 +0000] [1] [INFO] Shutting down: Master
ghc_web | [2021-12-21 09:28:22 +0000] [1] [INFO] Reason: Worker failed to boot.
ghc_web exited with code 3
Context (please complete the following information):
- OS: RaspberryPi OS
- docker: 20.10.12
- docker-compose: 1.29.2
Guess this is with the Docker Image built for ARM? NameError: name 'basestring' is not defined
, strange, is referred as error when running Python2 code on Python3 or with certain Python 3 versions. I tried running the same command on an empty Docker system with the standard GHC geopython/geohealthcheck:latest
without a problem.
Using Alpine for Python has more issues (one is massive slower builds) at least it is harder to get right. Recent versions of Docker Ubuntu and Debian (-slim) images are small as well. You may want to try.
In time we also want to migrate GHC Docker to Ubuntu or Debian.
I had this error on "normal" architecture on my laptop as well, but I could fix it by cleaning up my local Docker setup and re-downloading the GHC Docker image.
But I also have this problem on RaspberryPi with the base image arm32v7/python:3.7.9-alpine
Things I do not understand:
- I am running Python3 in the image. It is strange to me getting an Python 3 error 🤔
- The error is apparently connected with
psycopg
- however, I do use SQLite and not Postgres
I changed the context in the description to Raspberry Pi
Ok, I just found it this problem is not unique to Rpi. The latest GHC Docker Image running demo.geohealthcheck.org was just rebuilt (triggered by doc updates) and is now failing with similar error:
START /run-web.sh
Container timezone set to: Europe/London
START /configure.sh
Using DB_TYPE=postgresql
Check if Postgres is avail/ready...
ghc_demo_postgis:5432 - no response
Exit code=2 - Postgres not ready - sleeping
ghc_demo_postgis:5432 - accepting connections
Postgres is up - check if DB populated
count
-------
102
(1 row)
Postgres DB already populated
END /configure.sh
---> pavement.upgrade
Upgrading database...
cd /GeoHealthCheck/GeoHealthCheck
python manage.py db upgrade
2021-12-22 15:27:46,607 - init - INFO - created GHC App instance #1
Traceback (most recent call last):
File "manage.py", line 53, in <module>
manager.run()
File "/venv/lib/python3.7/site-packages/flask_script/__init__.py", line 417, in run
result = self.handle(argv[0], argv[1:])
File "/venv/lib/python3.7/site-packages/flask_script/__init__.py", line 386, in handle
res = handle(*args, **config)
File "/venv/lib/python3.7/site-packages/flask_script/commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "/venv/lib/python3.7/site-packages/flask_migrate/__init__.py", line 95, in wrapped
f(*args, **kwargs)
File "/venv/lib/python3.7/site-packages/flask_migrate/__init__.py", line 280, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "/venv/lib/python3.7/site-packages/alembic/command.py", line 320, in upgrade
script.run_env()
File "/venv/lib/python3.7/site-packages/alembic/script/base.py", line 563, in run_env
util.load_python_file(self.dir, "env.py")
File "/venv/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 92, in load_python_file
module = load_module_py(module_id, path)
File "/venv/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 108, in load_module_py
spec.loader.exec_module(module) # type: ignore
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "migrations/env.py", line 87, in <module>
run_migrations_online()
File "migrations/env.py", line 70, in run_migrations_online
poolclass=pool.NullPool)
File "/venv/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py", line 499, in engine_from_config
return create_engine(url, **options)
File "/venv/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py", line 456, in create_engine
return strategy.create(*args, **kwargs)
File "/venv/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/venv/lib/python3.7/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 737, in dbapi
import psycopg2
File "/venv/lib/python3.7/site-packages/psycopg2/__init__.py", line 68, in <module>
from psycopg2 import extensions as _ext
File "/venv/lib/python3.7/site-packages/psycopg2/extensions.py", line 211, in <module>
from psycopg2. _range import Range # noqa
File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 502, in <module>
oid=3904, subtype_oid=23, array_oid=3905)
File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 283, in __init__
self._create_ranges(pgrange, pyrange)
File "/venv/lib/python3.7/site-packages/psycopg2/_range.py", line 302, in _create_ranges
if isinstance(pgrange, basestring):
NameError: name 'basestring' is not defined
The failing build is not due to the changes, there is a problem in a unit test involving ArcGIS server...
So the fix, upgrading to psycopg2
2.9.2 works! @JakobMiksch : this may also now work for Docker on Raspberry Pi.