ssola / python-flask-microservice Goto Github PK
View Code? Open in Web Editor NEWSkeleton of a Microservice built with the Flask
License: Apache License 2.0
Skeleton of a Microservice built with the Flask
License: Apache License 2.0
I'm reading the first part of the tutorial. I cannot make run the flask microservice with the following command env FLASK_APP=app.py python -m flask run
.
Am I missing something?
From Flask document, app.run uses flask internal server is not recommended in production
Flask’s built-in server is not suitable for production as it doesn’t scale well and by default serves only one request at a time. Some of the options available for properly running Flask in production are documented here.
I think the sample code using a misleading deployment mechanism here and probabaly should be updated.
I'm getting the following error when trying to run docker-compose up
:
Attaching to pythonflaskmicroservice_elasticsearch_1, pythonflaskmicroservice_rabbitmq_1, pythonflaskmicroservice_our-app_1
our-app_1 | Failed to add operation for POST /1.0/room/
our-app_1 | Traceback (most recent call last):
our-app_1 | File "/code/app.py", line 31, in <module>
our-app_1 | app.add_api('indexer.yaml', resolver=RestyResolver('api'))
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/apps/flask_app.py", line 54, in add_api
our-app_1 | api = super(FlaskApp, self).add_api(specification, **kwargs)
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/apps/abstract.py", line 159, in add_api
our-app_1 | options=api_options.as_dict())
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 131, in __init__
our-app_1 | self.add_paths()
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 252, in add_paths
our-app_1 | self._handle_add_operation_error(path, method, sys.exc_info())
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 263, in _handle_add_operation_error
our-app_1 | six.reraise(*exc_info)
our-app_1 | File "/usr/local/lib/python3.6/site-packages/six.py", line 693, in reraise
our-app_1 | raise value
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 242, in add_paths
our-app_1 | self.add_operation(method, path, endpoint, path_parameters)
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/apis/abstract.py", line 195, in add_operation
our-app_1 | pythonic_params=self.pythonic_params)
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/operation.py", line 215, in __init__
our-app_1 | resolution = resolver.resolve(self)
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 40, in resolve
our-app_1 | return Resolution(self.resolve_function_from_operation_id(operation_id), operation_id)
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/resolver.py", line 62, in resolve_function_from_operation_id
our-app_1 | return self.function_resolver(operation_id)
our-app_1 | File "/usr/local/lib/python3.6/site-packages/connexion/utils.py", line 34, in get_function_from_name
our-app_1 | module = importlib.import_module(module_name)
our-app_1 | File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
our-app_1 | return _bootstrap._gcd_import(name[level:], package, level)
our-app_1 | File "<frozen importlib._bootstrap>", line 994, in _gcd_import
our-app_1 | File "<frozen importlib._bootstrap>", line 971, in _find_and_load
our-app_1 | File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
our-app_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
our-app_1 | File "<frozen importlib._bootstrap>", line 994, in _gcd_import
our-app_1 | File "<frozen importlib._bootstrap>", line 971, in _find_and_load
our-app_1 | File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
our-app_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
our-app_1 | File "<frozen importlib._bootstrap>", line 994, in _gcd_import
our-app_1 | File "<frozen importlib._bootstrap>", line 971, in _find_and_load
our-app_1 | File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
our-app_1 | File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
our-app_1 | File "<frozen importlib._bootstrap_external>", line 678, in exec_module
our-app_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
our-app_1 | File "/code/api/__init__.py", line 1, in <module>
our-app_1 | from api.room import Room
our-app_1 | File "/code/api/room.py", line 8, in <module>
our-app_1 | class Room(object):
our-app_1 | File "/code/api/room.py", line 9, in Room
our-app_1 | @inject(indexer=ElasticSearchIndex)
our-app_1 | File "/usr/local/lib/python3.6/site-packages/injector.py", line 1015, in inject
our-app_1 | 'Passing keyword arguments to inject is no longer supported. '
our-app_1 | AssertionError: Passing keyword arguments to inject is no longer supported. Use inject in combination with parameter annotations to declare dependencies. See documentation for details
pythonflaskmicroservice_our-app_1 exited with code 1
I always receive same response, seems I'm not using right endpoint.
Response:
{
"detail": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"status": 404,
"title": "Not Found",
"type": "about:blank"
}
Endpoints I have tried:
POST http://localhost:9091/api/room
POST http://localhost:9091/api/room/
POST http://localhost:9091/room
POST http://localhost:9091/room/
Also I can't access to swagger UI.
Any idea?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.