GAE Cloud endpoints not showing in the explorer - google-app-engine

i'm new to the cloud endpoint of GAE. I've made a small example, but it does not work,
this is the terminal output:
INFO 2014-04-17 16:34:50,293 sdk_update_checker.py:242] Checking for updates to the SDK.
INFO 2014-04-17 16:34:51,227 sdk_update_checker.py:286] This SDK release is newer than the advertised release.
WARNING 2014-04-17 16:34:51,240 api_server.py:374] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO 2014-04-17 16:34:51,244 api_server.py:171] Starting API server at: http://localhost:64102
INFO 2014-04-17 16:34:51,248 dispatcher.py:182] Starting module "default" running at: http://localhost:8080
INFO 2014-04-17 16:34:51,253 admin_server.py:117] Starting admin server at: http://localhost:8000
INFO 2014-04-17 16:34:58,926 module.py:627] default: "GET /_ah/api/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.5SU5w8-2ONg.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Fz%3Dzcms%2Frs%3DAItRSTMA_WMz6FduGUvb6_l_lrFfWB57ig HTTP/1.1" 200 7327
INFO 2014-04-17 16:34:59,038 module.py:627] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 404 -
INFO 2014-04-17 16:34:59,038 module.py:627] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 500 60
as you see there's a 404 and a 500, which i don't know why
this is the code i wrote:
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote
package = 'mypackage'
class YourResponseMessageClass(messages.Message):
message = messages.StringField(1)
#endpoints.api(name='myendpoint', version='v1')
class ExampleAPI(remote.Service):
#endpoints.method(message_types.VoidMessage,
YourResponseMessageClass,
name='foo.bar')
def user_get(self, request):
return YourResponseMessageClass(message="ciao")
APPLICATION = endpoints.api_server([ExampleAPI])
i've all the file in the same folder (can i move the api in subfolder btw?), and my yaml file looks like this:
application: ls-gae-api
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
# Endpoints handler
- url: /_ah/api/.*
script: myfile.APPLICATION
libraries:
- name: webapp2
version: "2.5.2"
- name: endpoints
version: 1.0

Correct path for Endpoints handler must be the following:
# Endpoints handler
- url: /_ah/spi/.*
script: myfile.APPLICATION
Note the spi part (you have api).

Related

deploying tornado on Google App Engine

I am trying to deploy my python pricing module which takes product details (string) as argument, on to GAE. The tornado wrapper is working fine on localhost (localhost:8888/?q=) but giving server error 500 on GAE.
Code in Pricing-OOP.py file:
class MainHandler(tornado.web.RequestHandler):
def get(self):
q = self.get_query_argument("q")
res = Pricing(q).pricing()
self.write(json.dumps(res))
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
],debug=True)
if __name__ == '__main__':
Pickleload()
app = make_app()
container = tornado.wsgi.WSGIContainer(app)
http_server = tornado.httpserver.HTTPServer(container)
http_server.listen(8888)
tornado.ioloop.IOLoop.current().start()
app.yaml file:
service: tornado
runtime: python27
threadsafe: no
handlers:
- url: /.*
script: Pricing-OOP.py
The gcloud app logs tail is as follows:
2017-07-26 03:03:30 tornado[20170726t082447] "GET / HTTP/1.1" 500
2017-07-26 03:03:30 tornado[20170726t082447] "GET /favicon.ico HTTP/1.1" 500
2017-07-26 03:03:33 tornado[20170726t082447] "GET / HTTP/1.1" 500
2017-07-26 03:03:34 tornado[20170726t082447] "GET /favicon.ico HTTP/1.1" 500
How do I correct this?
There are a few notes regarding deploying on Google App Engine in the Tornado docs.
In particular, a Tornado application on GAE must be run as a WSGI application. You cannot do things like open ports on the local machine,
and unfortunately it also prevents the use of asynchronous aspects of Tornado (which are often the main driver for using it in the first place).
In your case, instead of creating the HttpServer yourself, you should just create the WSGIAdapter:
# Pricing-OOP.py
# ...
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
],debug=False)
application = make_app()
application = tornado.wsgi.WSGIAdapter(application)
You then tell GAE where to find application by referencing it in the script directive of your configuration file:
# app.yaml
# ...
handlers:
- url: /.*
script: Pricing-OOP.application
Because you are now a "pure" WSGI application, you need to run it in a container. The Google Cloud SDK includes a development server in dev_appserver.py that can be used to host your app:
$ dev_appserver.py . # in directory containing app.yaml
That being done, you can run the same application code both locally and in your GAE instance.

Endpoints: /_ah/api/ returns 404 after update

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.

Google App Engine Guestbook application gives error

I upload the Google App Engine application which is at the url developers.google.com/appengine/docs/python/memcache/usingmemcache#Memcache
When I run the application on Google App Engine Launcher, it runs but the website shows:
(First error is there us no Python "PIL" module but I am not using image. Could you please suggest what is causing the error?
*** Running dev_appserver with the following flags:
--skip_sdk_update_check=yes --port=13080 --admin_port=8005
Python command: /usr/bin/python2.7
INFO 2014-01-17 20:43:22,217 devappserver2.py:660] Skipping SDK update check.
WARNING 2014-01-17 20:43:22,222 api_server.py:331] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO 2014-01-17 20:43:22,226 api_server.py:138] Starting API server at: localhost:55385
INFO 2014-01-17 20:43:22,230 dispatcher.py:171] Starting module "default" running at: localhost:13080
INFO 2014-01-17 20:43:22,238 admin_server.py:117] Starting admin server at: localhost:8005
ERROR 2014-01-17 20:43:24,601 wsgi.py:262]
Traceback (most recent call last):
File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 301, in _LoadHandler
raise err
ImportError: <module 'guestbookw2' from '/Users/guestbookw2/guestbookw2.pyc'> has no attribute application
INFO 2014-01-17 20:43:24,607 module.py:617] default: "GET / HTTP/1.1" 500 -
ERROR 2014-01-17 20:43:24,727 wsgi.py:262]
Traceback (most recent call last):
File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 301, in _LoadHandler
raise err
ImportError: <module 'guestbookw12' from '/Users/guestbookw2/guestbookw2.pyc'> has no attribute application
INFO 2014-01-17 20:43:24,732 module.py:617] default: "GET /favicon.ico HTTP/1.1" 500 -
Make sure that you have the following files in the path that you are uploading your application from:
index.yaml (auto-generated; you don't need to add or change anything in here at this point).
favicon.ico (in the correct format; should be 16x16 or 32x32 pixels if I remember correctly).
main.py (mapping all the paths in your web-site; example given below):
from webapp2 import WSGIApplication
from Server import MainRequestHandler
from Server import SomeRequestHandler
from Server import OtherRequestHandler
app = WSGIApplication([
('/' ,MainRequestHandler),
('/abc' ,SomeRequestHandler),
('/def' ,SomeRequestHandler),
('/xyz' ,OtherRequestHandler),
])
app.yaml (with the following contents; using <...> where you need to set a value):
application: <the app-id you chose when use signed in for GAE>
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" // you might need to change this as well
Note:
if you wish to avoid handling 'favicon.ico' request, then you must remove the reference in file 'app.yaml'.
Supplemental:
You will need to implement all the request handlers imported in 'main.py'.
In the example above, 'main.py' expects to find them in a Python module named 'Server'.
Each request handler must inherit class RequestHandler, imported from webapp2.
Supplemental #2:
In order to solve the 'PIL' issue (had a similar problem if memory serves correctly), simply install it.
From a Windows command line, enter: pip install pil.

Error running using web.py on Google App Engine - application instance has no __call__ method

I've been trying to use web.py to run a simple web app on Google App Engine but have been running into some pretty basic errors. I've searched over the site and haven't found anything to address my issue. Here is the outline of the code I'm trying to run:
import web
urls = (
"/","Index"
)
app = web.application(urls,globals())
render = web.template.render('pages/', base="layout")
class Index:
def GET(self):
#code...
if __name__ == "__main__":
app.cgirun()
and this is the app.yaml code:
application: #appname
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: home.app
- url: /static
static_dir: static
But then I get this in the log:
2013-08-22 06:11:13 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8000', 'C:\\.....\\root\\home-gae']"
INFO 2013-08-22 06:11:16,956 devappserver2.py:557] Skipping SDK update check.
WARNING 2013-08-22 06:11:16,976 api_server.py:317] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO 2013-08-22 06:11:17,006 api_server.py:138] Starting API server at: http://localhost:64510
INFO 2013-08-22 06:11:17,013 dispatcher.py:164] Starting module "default" running at: http://localhost:8080
INFO 2013-08-22 06:11:17,019 admin_server.py:117] Starting admin server at: http://localhost:8000
ERROR 2013-08-22 10:11:24,303 wsgi.py:235]
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\runtime\wsgi.py", line 223, in Handle
result = handler(dict(self._environ), self._StartResponse)
AttributeError: application instance has no __call__ method
INFO 2013-08-22 06:11:24,313 module.py:593] default: "GET / HTTP/1.1" 500 -
The AttributeError is confusing me because there does appear to be a call method in web/application module. Any ideas? Any thoughts would be appreciated.
I found a way to work it out.
import web
urls = (
"/.*", "hello"
)
application = web.application(urls, globals())
#app = web.application(urls, globals())
class hello:
def GET(self):
return "HelloWorld"
#app = app.gaerun()
#app.cgirun()
app = application.wsgifunc()
using "app = application.wsgifunc() ", then the code would work well.
First, there is a little problem with your app.yaml. You need to put your static handler before the catch-all handler:
handlers:
- url: /static
static_dir: static
- url: /.*
script: home.app
Otherwise, you will not be able to serve static files.
To fix your issue with the website not loading, it looks like the development server is trying to treat your CGI app as a WSGI app. Try to fit you home.py file to the official example for web.py on GAE. That is, get rid of the if __name__ == "__main__:" part and simply replace it with:
app = app.gaerun()

GAE: Why there is a constant POST request to /RPC2

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.

Resources