2 ModuleNotFoundErrors from newly generated python flask app on editor.swagger.io
Hello. Generated a flask app based off this spec https://w3c-ccg.github.io/vc-http-api/ which I've also attached from editor.swagger.io.
Unzipped and tried to run from the command line and I got
(TrustScience) daidoji@worklaptop:~/TrustScience/UCVDCC/w3c_issuer_verifier_api$ python -m swagger_server
Traceback (most recent call last):
File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/daidoji/TrustScience/UCVDCC/w3c_issuer_verifier_api/swagger_server/__main__.py", line 5, in <module>
from swagger_server import encoder
File "/home/daidoji/TrustScience/UCVDCC/w3c_issuer_verifier_api/swagger_server/encoder.py", line 1, in <module>
from connexion.apps.flask_app import FlaskJSONEncoder
ModuleNotFoundError: No module named 'connexion.apps'; 'connexion' is not a package
(TrustScience) daidoji@worklaptop:~/TrustScience/UCVDCC/w3c_issuer_verifier_api$ pip freeze | grep connexion
connexion==2.7.0
As you can see it can't find connexion but the module is installed.
If I try to run the docker image I get the following ModuleNotFound error for aiohttp.
(TrustScience) daidoji@worklaptop:~/TrustScience/UCVDCC/w3c_issuer_verifier_api$ docker build -t swagger_server .
Sending build context to Docker daemon 225.8kB
Step 1/9 : FROM python:3.6-alpine
---> 815c1103df84
Step 2/9 : RUN mkdir -p /usr/src/app
---> Using cache
---> a5c1dde011ee
Step 3/9 : WORKDIR /usr/src/app
---> Using cache
---> b209ff9a3946
Step 4/9 : COPY requirements.txt /usr/src/app/
---> Using cache
---> fb28d4e378c7
Step 5/9 : RUN pip3 install --no-cache-dir -r requirements.txt
---> Using cache
---> b80401c3389c
Step 6/9 : COPY . /usr/src/app
---> Using cache
---> 91d174e1ef74
Step 7/9 : EXPOSE 8080
---> Using cache
---> 30369ef0f4d7
Step 8/9 : ENTRYPOINT ["python3"]
---> Using cache
---> e9dbb9daf49e
Step 9/9 : CMD ["-m", "swagger_server"]
---> Using cache
---> ffecb8916be4
Successfully built ffecb8916be4
Successfully tagged swagger_server:latest
(TrustScience) daidoji@worklaptop:~/TrustScience/UCVDCC/w3c_issuer_verifier_api$ docker run -p 8080:8080 swagger_server
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/src/app/swagger_server/__main__.py", line 3, in <module>
import connexion
File "/usr/src/app/connexion.py", line 8, in <module>
import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
I have the same issue right now, did you happen to find the solution?
@hbot07 unfortunately I do not remember :-(
It may be due to absent of connexion.apps in the latest (or selected) versions of connexion package. There is a page v2.9.0, but not for v2.7.0. In your log we can see 2.7.0, where it's absent. https://connexion.readthedocs.io/en/2.9.0/autoapi/connexion/apps/ (ok) https://connexion.readthedocs.io/en/2.7.0/autoapi/connexion/apps/ (404 not found)
I had the same issue today, and this is a workaround i used to solve it : Open the "requirements.txt" file which present inside the unzipped folder named "python-flask-server-generated" and update the connexion version to "connexion >= 2.7.0, < 3.0.0" instead of "connexion >= 2.6.0"