python lxml unavailable in dev_appserver(gae,windows) - python

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.

Related

Python connexion not displaying Swagger UI

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.

How to 'pip install packages' inside Azure WebJob to resolve package compatibility issues

I am deploying a WebJob inside Azure Web App that uses Google Maps API and Azure SQL Storage.
I am following the typical approach where I make a WebJob directory and copy my 'site-packages' folder inside the root folder of the WebJob. Then I also add my code folder inside 'site-packages' and make a run.py file inside the root that looks like this:
import sys, os
sys.path.append(os.path.join(os.getcwd(), "site-packages"))
import aero2.AzureRoutine as aero2
aero2.run()
Now the code runs correctly in Azure. But I am seeing warnings after a few commands which slow down my code.
I have tried copying 'pyopenSSL' and 'requests' module into my site-packages folder, but the error persists.
However, the code runs perfectly on my local machine.
How can I find this 'pyopenSSL' or 'requests' that is compatible with the python running on Azure?
Or
How can I modify my code so that it pip installs the relevant packages for the python running on Azure?
Or more importantly,
How can I resolve this error?
#Saad,
If your webjob worked fine on Azure Web App, but you got inscuritywaring, I suggest you can try to disable the warning information via this configuration(https://urllib3.readthedocs.org/en/latest/security.html#disabling-warnings ).
Meanwhile,requests lib has some different with the high version, I recommend you refer to this document:
http://fossies.org/diffs/requests/2.5.3_vs_2.6.0/requests/packages/urllib3/util/ssl_.py-diff.html
And Azure web app used the Python 2.7.8 version which is lower than 2.7.9. So you can download the requests lib as version 2.5.3
According the doc referred in the warning message https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning:
Certain Python platforms (specifically, versions of Python earlier than 2.7.9) have restrictions in their ssl module that limit the configuration that urllib3 can apply. In particular, this can cause HTTPS requests that would succeed on more featureful platforms to fail, and can cause certain security features to be unavailable.
So the easiest way fix this warning, is to upgrade the python version of the Azure Web Apps. Login the Azure manager portal, change the python version to 3.4 in Application settings column:
As I test in webjob task to use requests module to request a "https://" url, and since upgrade python version to 3.4, there are no more warnings.
I followed this article and kind of 'pip installed' the pymongo library for my script. Not sure if it works for you but here are the steps:
Make sure you include the library name and version in the requirements.txt
Deploy the web app using Git. The directory should include at least
requirements.txt (only to install whatever is in requirements.txt in the virtual environment, which is shared with Web App in D:\home\site\wwwroot\env\Lib\site-packages)
add this block of code to the Python code you want to use in the WebJob zip file.
import sys
sitepackage = "D:\home\site\wwwroot\env\Lib\site-packages"
sys.path.append(sitepackage)

Error importing django-widget-tweaks on Google App Engine

I am deploying a Django app on Google App Engine, but I get an error when importing django-widget-tweaks:
appcfg.py: error: Error parsing ./app.yaml: the library "django-widget-tweaks" is not supported
Is there any way to fix this, apart from not using the library?
You can install third-party libraries yourself. Since this is not one of the runtime-provided third-party libraries you have to fulfill the following criteria:
The library must be implemented as pure Python code (no C extensions).
The code is uploaded to App Engine with your application code, and
counts toward file quotas.
Use pip to install the library and the
vendor module to enable importing packages from the third-party
library directory
From what I can tell the module you want to use is fully implemented in Python, so this should be straight forward. Consult the docs on vendoring for more information on how to do this.

Python - Configure gevent library on Google App Engine

I'm newbie in programming and need some help in the following situation.
I want to use gevent library on Google App Engine. I'm writing in Python using webapp2.
So the question is how to configure it so that it will work with GAE SDK.
I've put gevent library files in my projects directory like other libraries which are working well in this project. But when I run my app on local server it says:
ImportError: No module named greenlet
I've installed it on my computer,
pip install greenlet -t way/to/python/lib/directory
still it doesn't work
I had similar problem with lxml library, but It was solved after I've written its name in app.yaml. But lxml is preinstalled on GAE as written here. Although it's not the case with gevent.
I would appreciate any help. Thanks!

Does poster.encode module supported in python appengine?

Does poster.encode module supported in python appengine ??
if No , whats is the possible alternatives ?
You'd need to deploy the module with your code by including it in your application's directory when deploying, but it does appear to be a pure python module and looking through the source I see no reason why it wouldn't work just fine in App Engine.
The only modules that won't work are those that use C extensions or make use of features like threads, sockets, etc. that are disabled in the App Engine runtime. poster.streaminghttp, for example, almost certainly won't work, as it uses sockets.
from what I see in https://bitbucket.org/chrisatlee/poster/src/bd5ab4c5005c/poster/encode.py I doesn't see any class that would be forbidden by google app engine. Just upload it as any of your own code.

Categories