WSGI service setup fails

13 views
Skip to first unread message

Teemu Nuutinen

unread,
Jul 28, 2025, 7:56:44 AMJul 28
to Annif Users
Hello,
I am trying to set up Annif REST service by following the instructions here https://github.com/NatLibFi/Annif/wiki/Running-as-a-WSGI-service. The API localhost/v1/projects should return JSON but I only get 500 internal server errors. Apache error log:

[wsgi:error] [pid 2349:tid 140056305063616] [remote ::1:56518] mod_wsgi (pid=2349): Exception occurred processing WSGI script '/var/www/Annif/annif.wsgi'.
[wsgi:error] [pid 2349:tid 140056305063616] [remote ::1:56518] TypeError: AbstractApp.__call__() missing 1 required positional argument: 'send'

I tried this with Ubuntu 22, 24 and RedHat 9 and all fail with the same argument error. I'm not familiar with wsgi/flask/connexion setup and could use some help.

Example setup on Ubuntu 22 with python3.10:
# apt install apache2 libapache2-mod-wsgi-py3 curl python3-venv libvoikko1 voikko-fi
# addgroup --system annif
# adduser --system --home /srv/Annif --ingroup annif --shell /bin/bash annif
# mkdir /var/www/Annif
# cat > /var/www/Annif/annif.wsgi << EOF
import sys
sys.path.append('/srv/Annif/venv/lib/python3.10/site-packages')

from annif import create_app
application = create_app()
EOF
# su annif
$ cd ~
$ python3 -m venv venv
$ . venv/bin/activate
$ pip install pip wheel setuptools --upgrade
$ pip install annif[fasttext,omikuji,voikko]
$ python -m nltk.downloader punkt
...and followed by training or setting up pretrained data.

Uldis Bojars

unread,
Jul 29, 2025, 1:45:29 AMJul 29
to Teemu Nuutinen, Annif Users
Hi Teemu,

We had a similar error running a recent version of Annif.

It turned out we should not run Annif using WSGI because it is now async and we should use ASGI instead. 

Here is the command that we used to launch Annif (but I don't recall now if it worked OK or still had some issues):
gunicorn annif:create_app --bind 127.0.0.1:8000 -k uvicorn.workers.UvicornWorker

Uldis

--
You received this message because you are subscribed to the Google Groups "Annif Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to annif-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/annif-users/bc18ced1-99ad-49c7-baea-f0c46ca24523n%40googlegroups.com.

Osma Suominen

unread,
Jul 29, 2025, 9:32:52 AMJul 29
to annif...@googlegroups.com
Hi Teemu and Uldis,

you are both correct, the wiki page on WSGI is outdated and the recipes
no longer seem to work. I think this happened when Annif upgraded to
Connexion 3 (see this PR: https://github.com/NatLibFi/Annif/pull/702).

We are not currently using Annif as a WSGI service anywhere; we use
Docker containers for production services and "annif run" for testing
during development.

If any of you manage to get this working, it would be helpful if you
could share the details so that we can update the wiki page. In the
meantime, I put up a notice on the page saying it's out of date, with a
link to this discussion.

-Osma

On 28/07/2025 17:12, Uldis Bojars wrote:
> Hi Teemu,
>
> We had a similar error running a recent version of Annif.
>
> It turned out we should not run Annif using WSGI because it is now async
> and we should use ASGI instead.
>
> Here is the command that we used to launch Annif (but I don't recall now
> if it worked OK or still had some issues):
> gunicorn annif:create_app --bind 127.0.0.1:8000 <http://127.0.0.1:8000>
> -k uvicorn.workers.UvicornWorker
>
> Uldis
>
> On Mon, 28 Jul 2025 at 14:56, Teemu Nuutinen <tsnu...@gmail.com
> <mailto:tsnu...@gmail.com>> wrote:
>
> Hello,
> I am trying to set up Annif REST service by following the
> instructions here https://github.com/NatLibFi/Annif/wiki/Running-as-
> a-WSGI-service <https://github.com/NatLibFi/Annif/wiki/Running-as-a-
> WSGI-service>. The API localhost/v1/projects should return JSON but
> <mailto:annif-users...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> annif-users/bc18ced1-99ad-49c7-baea-f0c46ca24523n%40googlegroups.com
> <https://groups.google.com/d/msgid/annif-users/bc18ced1-99ad-49c7-
> baea-f0c46ca24523n%40googlegroups.com?
> utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Annif Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to annif-users...@googlegroups.com <mailto:annif-
> users+un...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/annif-
> users/CAJjMrEN2_SRH-
> A9J374p7asa4_L2VfF6ArDV3Nq66CYCURv%3DgA%40mail.gmail.com <https://
> groups.google.com/d/msgid/annif-users/CAJjMrEN2_SRH-
> A9J374p7asa4_L2VfF6ArDV3Nq66CYCURv%3DgA%40mail.gmail.com?
> utm_medium=email&utm_source=footer>.

--
Osma Suominen
D.Sc. (Tech), Information Systems Specialist
National Library of Finland
P.O. Box 15 (Unioninkatu 36)
00014 HELSINGIN YLIOPISTO
Tel. +358 50 3199529
osma.s...@helsinki.fi
http://www.nationallibrary.fi

Reply all
Reply to author
Forward
0 new messages