I currently have an API that looks like this (for testing):
from flask_restful import Resource, request
class UploadFile(Resource):
def get(self):
pass
def post(self):
is_header_present(request.headers, "User-Agent", None)
def is_header_present(headers, search_term, correct_variable):
for header in headers.keys():
print(header)
While running this API using the following code:
from flask import Flask
from flask_restful import Api
from lib.api import UploadFile
app = Flask(__name__)
api = Api(app)
api.add_resource(UploadFile, "/cas", methods=["GET", "POST"])
app.run(
host="127.0.0.1", port=6823
)
I get the following error:
Traceback (most recent call last):
File "cas.py", line 262, in <module>
from flask import Flask
File "/home/sal/.local/lib/python3.6/site-packages/flask/__init__.py", line 16, in <module>
from werkzeug.exceptions import abort
File "/home/sal/.local/lib/python3.6/site-packages/werkzeug/__init__.py", line 15, in <module>
from .serving import run_simple
File "/home/sal/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 50, in <module>
from ._internal import _log
File "/home/sal/.local/lib/python3.6/site-packages/werkzeug/_internal.py", line 11, in <module>
import inspect
File "/usr/lib/python3.6/inspect.py", line 36, in <module>
import dis
File "/usr/lib/python3.6/dis.py", line 9, in <module>
from opcode import __all__ as _opcodes_all
ImportError: cannot import name '__all__'
My current installation versions of Flask, flask_restful, and Werkzeug are as follows:
- Flask==2.0.3
- Flask-RESTful==0.3.9
- Werkzeug==2.0.3
I have never encountered this error before so I'm not sure what to do, and it seems that Googling the error produces no results for the issue. How can I fix this error and continue?
My python version is: 3.6.9
I tried reinstalling the libraries, I tried Googling for a fix, I also tried reinstalling python.