It seems lxml is not available for me in dev_appserver. I have test project is import lxml line built with windows python sdk 1.6.6. "No module named lxml". I assume something with installed version of python, but I have Python 2.7.
import webapp2
import lxml
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write('Hello world!')
app = webapp2.WSGIApplication([('/', MainHandler)],
debug=True)
===
application: teslxml
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.1"
- name: lxml
version: latest
==
dev_appserver.py teslxml
Update: This isn't true anymore, lxml is now shipped out of the box.
https://cloud.google.com/appengine/docs/standard/python/tools/built-in-libraries-27
lxml doesn't come out of the box with Google App Engine, you need to install it.
I kept getting the 'no module named lxml' error, but was unable to install the module separately and I resolved this by telling pip to install with a specific version number, like so;
pip install lxml==[versionnumber]
Related
I am servicing a system.
An old App Engine tool was used to deploy, but it is now obsolete and I need to use the gcloud command line.
However, gcloud is ignoring one system folder and deploying all others.
One big reason this must be happening is because they developed this system based on node_modules and didn't build the code before uploading. In short, I need the node_modules folder for the code to execute.
I already disabled .gcloudignore, but there have been no changes.
Source folder structure:
Folder Structure in App Engine:
I ran the --verbosity = info code on my gcloud deploy and it appeared that they were ignoring it:
My app.yaml:
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: jinja2
version: 2.6
- name: lxml
version: 2.3
- name: pycrypto
version: 2.6
handlers:
- url: /static
static_dir: app/static
secure: always
- url: /.*
script: manage.app
secure: always
builtins:
- remote_api: on
By default, flask use a "templates" folder to contain all your template files(any plain-text file, but usually .html or some kind of template language such as jinja2 ) & a "static" folder to contain all your static files(i.e. .js .css and your images).
So ideally you should not use /static folder
you will need to update app.yaml to include handler static_dir: static
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: ssl
version: latest
# [START handlers]
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.app
# [END handlers]
The best way to use is
from flask import Flask
app = Flask(__name__, static_folder='static', static_url_path='')
Problem fixed via Google Cloud support:
I removed the /_ah/spi/* handler from my endpoints yaml file, and the
- url: /.*
script: api.app
did not instantiate the endpoint.
It used to work before since the API was deployed for the previous version, but with the new version, there was nothing explicit to deploy the endopoints. So handlers need to be
handlers:
- url: /_ah/spi/.*
script: api.app
- url: /.*
script: api.app
Keeping the issue below for reference purposes
I've just deployed a new version of my application, and calls to http://app.appspot.com/_ah/api/app/version/method now return a 404. It worked perfectly before the update.
However, there's no trace at all in the logs, and no instance launched when I call/ping those URIs.
While if I call /_ah/whatever/app/version/method, I still have a 404, but it appears in my module logs, and it has the following message
{"state": "APPLICATION_ERROR", "error_message": "Not Found"}
The app is configured using modules, my app.yaml is defined with
application: appname
version: 2015-04-07
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /_ah/spi/.*
script: api.api.app
- url: /.*
script: www.www.app
secure: always
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
- name: webapp2
version: latest
- name: jinja2
version: latest
And, in api/api.yaml
application: appname
module: default
version: 2015-04-07
runtime: python27
api_version: 1
threadsafe: true
inbound_services:
- warmup
handlers:
- url: /.*
script: api.app
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
- name: ssl
version: latest
I've updated the app to serve this new version in the admin console, and all other modules work perfectly.
Also, I can't see my API in the API explorer, https://appname.appspot.com/_ah/api/explorer returns an empty list (while I see it when running the dev server on localhost).
Update: I've just noticed, looking at #bossylobster reply in GAE cloud endpoints - Api not updating after deploy, that I do not have "Successfully updated API configuration" in my logs after the "Completed update of a new alternate version". However, I have "API deletion serving" at about the time everything started to be 404. Yet, I have no idea why there's this API deletion query in my logs. Any idea of what can be wrong?
That's an app in production and so the mobile version is down at the moment. I'm happy to send the app ID to a devrel in PM if that helps.
I'm new to Google app engine not new to Python, there is a very confusing problem to me.
First of all, show you my version.
The problem is when I run the development server, there is a constant POST request to /PRC2, I have no idea where it came from.
See the screenshot below.
My main.py
from google.appengine.ext import webapp
import os
from handlers import MainHandler
CURRENT_VERSION_ID = os.environ.get('CURRENT_VERSION_ID', None)
if os.environ.get('SERVER_SOFTWARE', '').startswith('Google App Engine'):
DEVELOPMENT = False
else:
DEVELOPMENT = True
config = {
'DEBUG': DEVELOPMENT
}
routes = [
(r'/', MainHandler), # Homepage
]
app = webapp.WSGIApplication(
routes, debug=DEVELOPMENT, config=config
)
And app.yaml
application: xxxxxxxxxxxx
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.app
libraries:
- name: webapp2
version: "2.5.1"
- name: jinja2
version: "2.6"
Strange. Try another port and look if you keep this strange POST. Or serve the post in your app and look what is in the request, to find out where it comes from.
You're probably launching dev_appserver on some port where an XML-RPC application is looking for a particular API.
I have seen posts in Google Groups and here that mention using xlrd in Google App Engine:
How do you read excel files with xlrd on Appengine
https://groups.google.com/forum/?fromgroups=#!searchin/google-appengine-python/xlrd/google-appengine-python/lMix6vXhvtA/O_ExzkGhsKEJ
but when I try to add it to the app.yaml file, it says "the library xlrd is not supported". Also, in the list of 3rd party libraries I don't see xlrd.
https://developers.google.com/appengine/docs/python/tools/libraries27
But then other people seem to be using it on GAE, so does GAE support it or not? In the past I was able to import numpy successfully. Here is app.yaml. On main.py I have "import xlrd". Thank you very much.
application: uploadsample
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.1"
- name: xlrd
version: "0.7.3"
You can include any pure python third-party libraries with your app that you want. You don't specify them in app.yaml, that's only for third-party libraries that are included by Google on the servers.
xlrd is not "supported" per se, but it should work.
I have tried to move to Python 2.7 from Python 2.5 but I keep getting the same error everytime.
I have made a very simple test in Python 2.5 working with the app.yaml file and just one script main.py and it works fine. The script it just a Hello World type to check everythin works fine.
app.yaml
application: sparepartsfinder
version: 1
runtime: python
api_version: 1
handlers:
- url: /blog
script: main.py
- url: /blog/new_entry
script: main.py
main.py
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication(
[('/', MainPage),
('/blog', MainPage),
('/blog/new_entry',MainPage),
('/blog/archive/.*',MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
When I change to Python 2.7 I follow the documents on the Google App Engine to the letter making the changes in both the app.yaml and main.py script.
app.yaml
application: sparepartsfinder
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /blog
script: main.py
- url: /blog/new_entry
script: main.py
- url: /blog/archive/.*
script: main.py
- url: .*
script: main.py
main.py
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write('Hello prueba!')
app = webapp2.WSGIApplication([('/', MainPage),
('/blog', MainPage),
('/blog/new_entry',MainPage),
('/blog/archive/.*',MainPage)],
debug=True)
Unfortunately it doesn't work either in local or when I try to upload the new configuration to the Google App Engine. ( I get always the same mistake).
I may understand the problem in my machine ( I have both Python 2.5 and 2.7 ) on a Windows XP, but not when I upload.
This is the error:
2012-05-04 13:02:07 Running command: "[u'C:\Python25\python2.5.exe', '-u', 'C:\Archivos >de programa\Google\google_appengine\appcfg.py', '--no_cookies', u'--email=salvador.sanjuan#gmail.com', '--passin', 'update', 'C:\Documents and Settings\SSanjuan\Mis documentos\Dropbox\Dropbox\Python\SpareParts']"
Error parsing yaml file:
Invalid object:
threadsafe cannot be enabled with CGI handler: main.py
in "C:\Documents and Settings\SSanjuan\Mis documentos\Dropbox\Dropbox\Python\SpareParts\app.yaml", line 27, column 1
2012-05-04 13:02:31 (Process exited with code 1)
Use main.application instead of main.py in your app.yaml. You need the former in order to set threadsafe to true.
I've been having the same problem, and here's the answer.
For the Python 2.5 runtime, you are specifying a path to a file -- ie script: myfolder/myfile.py.
For the Python 2.7 runtime, you are specifying an Object. So assumping myfile.py contains an appropriate WSGI object 'app', it's specified as script: myfolder.myfile.app.