I've built a Python/Flask based REST API using the connexion module. This working well as defining the REST API with with swagger.yml file works very well. The application is running, but when I navigate to /ui all I get in my browser is this:
I haven't disabled the UI, so I'm not sure what's going on and why the UI isn't being displayed. My application doesn't have a /static folder (it's only an API), so the app isn't serving any static files, not sure if that's related to the problem or not.
Any suggestions, pointers or hints about what I'm doing wrong would be most appreciated!
Here is a simplified example of my code:
# 3rd party libraries
from flask_cors import CORS
import connexion
def create_app(config_key, instance_config=None):
# create the connexion instance
connex_app = connexion.FlaskApp(__name__, specification_dir='./files/swagger/')
connex_app.server = 'gevent'
# get the Flask app instance
app = connex_app.app
# configure the application
app.config.from_object(config_key)
# add CORS support to application
CORS(app)
# define the API with the SWAGGER API definition YAML file
connex_app.add_api('line_controller_api.yml',
base_path='{url_prefix}'.format(url_prefix=app.config.get('URL_PREFIX', '/')),
resolver=AppResolver())
return connex_app
def production_app(instance_config=None):
app = create_app('api_config.ProductionConfig', instance_config)
return app
if __name__ == '__main__':
app = create_app('api_config.DevelopmentConfig')
port = 5001
logger.info('Line Controller API running on port %s', port)
app.run(host='0.0.0.0', port=port)
Thanks in advance,
Doug
connexion from 2.0.1 version onward don't have swagger-ui bundled inside it. You have install it explicitly using the below command (note the quotes)
pip install 'connexion[swagger-ui]'
Once you install it. swagger will work with connexion. In the earlier version swagger used to work with /ui added to your url at the end http(s)://host:port
But in 2.0.x onward use http(s)://host:port/<basepath>/ui
My stackoverflow reputation is too low for me to comment on Ashraff Ali Wahab's answer above but I just found out that I can edit it myself. Suffice it to say that it fixed the problem for me after I understood that the shell syntax, as presented, is wrong which was pointed out by Pablo Marin-Garcia. This is the shell syntax you need in Unix/Linux to properly install the swagger-ui plugin:
pip install 'connexion[swagger-ui]'
Any matched quotes will do. Note well that without the quotes, the pip command will run successfully but it won't install the swagger-ui component as you expect it to. Furthermore, I spent a lot of time scratching my head on this one because I did this in a virtualenv. I also searched the virtualenv for the swagger-ui component with find and I found some stub installed. So, if you are new to python or you are in a hurry, this can be easy to miss.
At the end of the day, I decided to add a local_requirement.txt file listing the correct version of Werzueg, connexion, and "connexion[swagger-ui]" which I install before using the stock requirements.txt because it seems like the Flask API code generated by the SmartBear tools is a little dated.
I had the same problem. I solved it with
pip install pathlib swagger_ui_bundle
It's caused by missing trailing slash. Just add slash at the end of your url and it will work.
Related issue https://github.com/zalando/connexion/issues/346.
Related
I have generated a simple API server example using swaggerhub, and downloaded python-flask generated server locally.
Unfortunately, it seems to not work at all. Every time I try to access the indicated url, that is
http://localhost:8080/data/2.5//ui/
it returns me a 404 error.
I've tried all the solutions reported on:
Python connexion not displaying Swagger UI
but with no success. What am I missing?
A very simple detail that made all work: after executing pip install 'connexion[swagger-ui]' and pip install pathlib swagger_ui_bundle (though I am not sure the last is strictly needed...), the server worked only with an invalidate cache and restart command on PyCharm.
I want to use Braintree in my Django app that's running in Heroku, I made it work locally, but, when I push my app to Heroku, I get an error.
I'm pretty sure that the problem is that I don't import Braintree to my requirements.txt, so...
How can I make Braintree work in Heroku?
Add Braintree to requirements.txt. Something like
Braintree==<verson_here>
Just append that to requirements.txt, you can know what version by running:
pip freeze
And this, will give you a list of all the external packages that you have installed. An example screenshot:
Also as a side note, make sure that you add all the things listed when you get your output from pip freeze, so that no dependencies are lacking if there are any.
I have installed lxml yet.
It works fine in IDLE.
But when I start an basic app described below with dev_appserver.py ,server returns error "No module named lxml".
import webapp2,lxml
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write("test")
app = webapp2.WSGIApplication([("/(.*)", MainPage)],debug=True)
How can I resolve this??
Thanks!!
Assumingly you're using Python 2.7 runtime. This runtime provides a fine way for configuring libraries.
Please add libraries section in your app.yaml as follows:
libraries:
- name: lxml
version: latest
For more details, please see:
https://developers.google.com/appengine/docs/python/python27/using27#Configuring_Libraries
Any python library you use will need to be in your app folder - otherwise, it won't work when deployed, because only your app folder is deployed to App Engine. You'll need to put a copy of lxml in your app folder.
Secondly though, I don't think lxml will work at out, since it runs on top of C libraries, and only pure python projects work on App Engine.
I am trying to use Bulkloader of google app engine but unfortunately could not understand what to do from documentation. It says add this part to app.yaml
builtins:
- remote_api: on
ok i have added. Then says that i have to execute this command
appcfg.py update
but i don't have any appcfg.py file. And also what is the command which executes this line?
Please somebody tell me what i am missing I use AppEngineLauncher to upload my project to server.. I have naver used a command to update or upload it.
Thanks in advance..
If you're using App Engine Launcher, simply click the Deploy button; it runs appcfg.py update. appcfg is installed as part of the SDK.
In order to call it globally you must set the python path to include google appengine library, or call it from its excact location
~/google_appengine/appcfg.py update ~/project/path_to_your_yaml_file/
where ~ stands for you home folder.
For those using the the Java GAE SDK, it comes wtih appcfg.sh, but doesn't support full features of apppcfg.py. You need to also install the Python GAELauncher. On Mac, it installs appcfg.py in /usr/local/bin.
Working only with my local datastore, I did not have an app.yaml, nor did I need to update it as per the uploading data GAE documentation. Just needed to update the web.xml with the RemoteApiServlet.
Main gotcha is the Authentication error while connecting to the local data store. It may be specific to Mac and the Charles proxy work around mentioned in that thread likewise worked for me. I did have to modify the default proxy port from 8888 to avoid conflict with my app. The workaround is tedious and the trial version of Charles comes with limitations such as shutdown after 30 minutes.
To use the main database for development, first download it from app engine:
bulkloader.py --dump --url http://<app name>.appspot.com/_ah/remote_api --filename dump.bin
It will ask for an email and password (use your google login details).
To upload it to the development environment, make sure remote_api is
enabled in app.yaml
https://developers.google.com/appengine/docs/python/tools/uploadingdata#Setting_Up_remote_api
Then run:
bulkloader.py --restore --url http://localhost:8080/_ah/remote_api --filename dump.bin --application dev~<app name>
This time for the email, just leave it blank and hit enter.
I've downloaded google_appengine version 1.3.1. Using some web tutorials, I've created basic django 1.1.1 application. Using appcfg I managed to deploy it on GAE and it works. The problem is, that application doesn't want to work on dev_appengine.py developement server.
Whenever I run the app GAE local server is returning HTTP 200 without any content. If I set basic environement and run main.py manually, then the page is properly returned on stdout.
I've also created very basic helloworld application, and this one is working ok on the devel server.
Do you have any idea, how can I debug the devel server? Option -d doesn't give any usefull insight at all.
I had module nammed same way as the default GAE launcher (main/ and main.py). After renaming the launcher everything works great.