Errors

Page content

Misc Errors and Solutions

Flask & sqlalchemy

(flask-tables-py3.10) user@host ../flask-tables> python create_fake_users.py 5
Traceback (most recent call last):
  File "/Users/stoege/git/mpr_2023Q1/flask-tables/create_fake_users.py", line 6, in <module>
    from bootstrap_table import User, db
  File "/Users/stoege/git/mpr_2023Q1/flask-tables/bootstrap_table.py", line 18, in <module>
    db.create_all()
  File "/Users/stoege/git/mpr_2023Q1/flask-tables/.venv/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 868, in create_all
    self._call_for_binds(bind_key, "create_all")
  File "/Users/stoege/git/mpr_2023Q1/flask-tables/.venv/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 839, in _call_for_binds
    engine = self.engines[key]
  File "/Users/stoege/git/mpr_2023Q1/flask-tables/.venv/lib/python3.10/site-packages/flask_sqlalchemy/extension.py", line 628, in engines
    app = current_app._get_current_object()  # type: ignore[attr-defined]
  File "/Users/stoege/git/mpr_2023Q1/flask-tables/.venv/lib/python3.10/site-packages/werkzeug/local.py", line 513, in _get_current_object
    raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.

Solution

https://stackoverflow.com/questions/34122949/working-outside-of-application-context-flask

-> Downgrade flask-sqlalchemy to 2.5.1

# Downgrade Flask Version
gsed -i 's/flask-sqlalchemy.*/flask-sqlalchemy = "~2.5.1"/' pyproject.toml

# Rebuild Lock
poetry lock

# Install Packages
poetry install

# run again
python create_fake_users.py 5

Gitlab on Vultr

Created a Gitlab Instance on Vultr for testing Reason. Seems all fine, except:

root@gitlab:~# apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu focal-security InRelease
Get:2 https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu focal InRelease [23.3 kB]
Err:2 https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu focal InRelease
  The following signatures were invalid: EXPKEYSIG 3F01618A51312F3F GitLab B.V. (package repository signing key) <packages@gitlab.com>
Fetched 23.3 kB in 2s (11.0 kB/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu focal InRelease: The following signatures were invalid: EXPKEYSIG 3F01618A51312F3F GitLab B.V. (package repository signing key) <packages@gitlab.com>
W: Failed to fetch https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/dists/focal/InRelease  The following signatures were invalid: EXPKEYSIG 3F01618A51312F3F GitLab B.V. (package repository signing key) <packages@gitlab.com>
W: Some index files failed to download. They have been ignored, or old ones used instead.

Solution

curl -s https://packages.gitlab.com/gpg.key | apt-key add -
apt-get update
apt-get upgrade

Selfsigned Cert

gitlab has got a selfsigned cert on gitlab sever. like to change this.

Solution

cd /etc/gitlab/
cp gitlab.rb gitlab.rb.bak
sed -i 's/^external_url.*/external_url "https:\/\/gitlab.your.domain.net"/' gitlab.rb
sed -i "s/^# letsencrypt\['auto_renew'\].*/letsencrypt['auto_renew'] = true/" gitlab.rb
sed -i "s/^# letsencrypt\['contact_emails'\].*/letsencrypt['contact_emails'] = ['domains@your.domain.net']/" gitlab.rb
git diff gitlab.rb.*
gitlab-ctl reconfigure

Airflow Root Login

you have Airflow running on Docker and not root login ?

docker exec -u root -ti airflow-airflow-scheduler-1 bash

Solution then, you can install all the stuff you need and fix your problems

apt-get update
apt-get upgrade
apt-get install htop lsof tree procps tcpdump net-tools mlocate dnsutils
updatedb

cron & poetry

you wanna run a python script via poetry as cronjob and you get the following error:

# cronjob as root
* * * * * cd /path/to/your/script; poetry run mycode > out 2>&1

# error
Traceback (most recent call last):
  File "/usr/local/bin/poetry", line 5, in <module>
    from poetry.console.application import main
  File "/usr/local/lib/python3.9/site-packages/poetry/console/application.py", line 19, in <module>
    from poetry.__version__ import __version__
  File "/usr/local/lib/python3.9/site-packages/poetry/__version__.py", line 5, in <module>
    from poetry.utils._compat import metadata
  File "/usr/local/lib/python3.9/site-packages/poetry/utils/_compat.py", line 20, in <module>
    import importlib_metadata as metadata
  File "/usr/local/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 6, in <module>
    import zipp
ModuleNotFoundError: No module named 'zipp'

**Solution**
-> set HOME as the Virtual Env is located here
* * * * * export HOME=/root; cd /path/to/your/script; poetry run mycode > out 2>&1

gpg on OpenBSD 7.4

test1@puffy $ gpg --generate-key 
gpg (GnuPG) 2.4.3; Copyright (C) 2023 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Note: Use "gpg --full-generate-key" for a full featured key generation dialog.

GnuPG needs to construct a user ID to identify your key.

Real name: user1
Email address: user1@puffy205
You selected this USER-ID:
    "user1 <user1@puffy205>"

Change (N)ame, (E)mail, or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: agent_genkey failed: Permission denied
Key generation failed: Permission denied

seems a permission error ?!? ktrace / kdump did not help. When i allow the User for doas (root), it seems working.

solution build the key in tmux (proper handling of ownership with terminal-related device file)

tmux
gpg --generate-key

hint

ls -l $(tty)
crw--w----  1 stoege  tty    5,   0 Jan  2 09:25 /dev/ttyp0

vs

tmux
ls -l $(tty)
crw--w----  1 test1  tty    5,   1 Jan  2 09:27 /dev/ttyp1

SQL Alchemy2 on OpenBSD 7.4 / 7.5 Beta

root@yourhost /tmp/guguseli# poetry add pydantic
Using version ^2.6.4 for pydantic

Updating dependencies
Resolving dependencies... (1.2s)

Package operations: 2 installs, 0 updates, 0 removals

  - Installing pydantic-core (2.16.3): Failed

  ChefInstallError

  Failed to install typing-extensions >=4.6.0,!=4.7.0, maturin>=1,<2.

  Output:
  Updating dependencies
  Resolving dependencies...

  Package operations: 3 installs, 0 updates, 0 removals

    - Installing tomli (2.0.1)
    - Installing maturin (1.5.1)
    - Installing typing-extensions (4.10.0)

    ChefBuildError

    Backend subprocess exited when trying to invoke build_wheel

    /tmp/tmp90xuiusw/.venv/lib/python3.10/site-packages/setuptools/config/_apply_pyprojecttoml.py:83: SetuptoolsWarning: `install_requires` overwritten in `pyproject.toml` (dependencies)
      corresp(dist, value, root_dir)
    running bdist_wheel
    running build
    running build_py
    creating build
    creating build/lib.openbsd-7.5-amd64-cpython-310
    creating build/lib.openbsd-7.5-amd64-cpython-310/maturin
    copying maturin/__init__.py -> build/lib.openbsd-7.5-amd64-cpython-310/maturin
    copying maturin/__main__.py -> build/lib.openbsd-7.5-amd64-cpython-310/maturin
    copying maturin/import_hook.py -> build/lib.openbsd-7.5-amd64-cpython-310/maturin
    running egg_info
    creating maturin.egg-info
    writing maturin.egg-info/PKG-INFO
    writing dependency_links to maturin.egg-info/dependency_links.txt
    writing requirements to maturin.egg-info/requires.txt
    writing top-level names to maturin.egg-info/top_level.txt
    writing manifest file 'maturin.egg-info/SOURCES.txt'
    reading manifest file 'maturin.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching '*.json' under directory 'src/python_interpreter'
    writing manifest file 'maturin.egg-info/SOURCES.txt'
    running build_ext
    running build_rust
     Downloading crates ...
    error: failed to wait on curl `Multi`

    Caused by:
      Unrecoverable error in select/poll
    error: `cargo metadata --manifest-path Cargo.toml --format-version 1 --locked` failed with code 101
    -- Output captured from stdout:

Solution

root@yourhost # ulimit -n 1024
root@yourhost # poetry add pydantic
... here we are ...

Debug PIP Stuff

pip debug --verbose

Cryptography on OpenBSD 7.5

have not been able to add/build cryptography package for python. independent of the version, it fails

poetry add cryptography

--- snip ---

 Caused by:
    process didn't exit successfully: `/tmp/tmpqohhf36y/cryptography-42.0.7/src/rust/target/release/build/cryptography-cffi-69dd56dd49fae026/build-script-build` (exit status: 101)
    --- stdout
    cargo:rustc-check-cfg=cfg(python_implementation, values("CPython", "PyPy"))
    cargo:rerun-if-env-changed=PYO3_PYTHON
    cargo:rerun-if-changed=../../_cffi_src/
    cargo:rerun-if-changed=../../cryptography/__about__.py
    cargo:rustc-cfg=python_implementation="CPython"

    --- stderr
    thread 'main' panicked at cryptography-cffi/build.rs:63:49:
    unable to find openssl include path
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  warning: build failed, waiting for other jobs to finish...
  error: `cargo rustc --lib --message-format=json-render-diagnostics --manifest-path src/rust/Cargo.toml --release -v --features pyo3/extension-module --crate-type cdylib --` failed with code 101


  at ~/.local/lib/python3.10/site-packages/poetry/installation/chef.py:164 in _prepare
      160│
      161│                 error = ChefBuildError("\n\n".join(message_parts))
      162│
      163│             if error is not None:
    → 164│                 raise error from None
      165│
      166│             return path
      167│
      168│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with cryptography (42.0.7) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "cryptography (==42.0.7)"'.

Solution

export OPENSSL_DIR="/usr"
poetry add cryptography
puffyhost$ poetry install            
Installing dependencies from lock file

Package operations: 1 install, 0 updates, 0 removals

  - Installing cryptography (42.0.7): Preparing...
  - Installing cryptography (42.0.7)

Debian - Fix APT Error (Download is performed unsandboxed as root)

https://medium.com/@danielfrey1986/fix-apt-error-download-is-performed-unsandboxed-as-root-6fb6773a8c91

echo 'APT::Sandbox::User "root"' >> /etc/apt/apt.conf.d/10sandbox
apt update
apt upgrade

Debian - Fix Locale

got the Errors:

-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8)
localedef -i en_US -f UTF-8 en_US.UTF-8

logout, login, fixed

PIP externally managed

root@puffy /data/myproject# pip3 install -r requirements/requirements.txt
error: externally-managed-environment

× This environment is externally managed
╰─> This Python installation is managed by pkg_add(1).
    
    To install Python packages system-wide, use the OS packages where
    possible, for example: "pkg_add py3-somepackage".
    
    Otherwise, for software which is not available in packages,
    it is recommended to create a "venv" (virtual environment, see
    https://docs.python.org/3/library/venv.html) and install it there.
    For standalone applications, pipx (in the py3-pipx package) can
    help manage this for you.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
mv /usr/local/lib/python3.10/EXTERNALLY-MANAGED /usr/local/lib/python3.10/EXTERNALLY-MANAGED.bak
mv /usr/local/lib/python3.11/EXTERNALLY-MANAGED /usr/local/lib/python3.11/EXTERNALLY-MANAGED.bak

or

mkdir -p ~/.config/pip/
cat << 'EOF' >> ~/.config/pip/pip.conf
[global]
break-system-packages = true
EOF

Any Comments ?

sha256: 544f583153ef22c57986f77c05e773d507c695bac36353a08c02e7ad4548704f