Google App Engine - Endpoints Failure - python

I'm trying to deploy a gae project with endpoints but it's giving me errors that's should be happening.
I Don't Think there is anything wrong with my code but i keep getting this error when trying to deploy:
There is a /_ah/spi handler configured, but no Google Cloud Endpoints service was found in the app
my app.yaml :
application: app-id
version: 1
runtime: python27
api_version: 1
threadsafe: true
# --- Handlers
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
secure: always
- url: /js
static_dir: static/js
- url: /img
static_dir: static/img
- url: /css
static_dir: static/bootstrap/css
- url: /fonts
static_dir: static/fonts
- url: /partials
static_dir: static/partials
- url: /_ah/spi/.*
script: game.api
secure: always
# --- Libraries
libraries:
- name: webapp2
version: "2.5.2"
- name: pycrypto
version: latest
- name: endpoints
version: latest
- name: jinja2
version: latest
and my game.py :
from datetime import datetime
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote
from google.appengine.api import memcache
from google.appengine.api import taskqueue
from google.appengine.ext import ndb
# --- Setup Code
WEB_CLIENT_ID = 'app-id'
# --- Classes
class Hello(messages.Message):
"""String that stores a message."""
greeting = messages.StringField(1)
class TestOne(messages.Message):
''' TestOne message '''
msg = messages.StringField(1)
# --- API & Endpoints
#endpoints.api(name='whoamigame', version='v1')
class WhoAmIGameApi(remote.Service):
#endpoints.method(message_types.VoidMessage, TestOne, path='testone', http_method='GET', name='testonemethod')
def testOneM(self, req):
testOneMsgReturn = TestOne(msg='Test One...')
return testOneMsgReturn
# --- API
api = endpoints.api_server([WhoAmIGameApi])
Every time i try to deploy it, the endpoints fail. i'm not sure how to fix this issue. the code and syntax is perfect to me. everything is defined. the sdk fails every time.

Related

Google App Engine failed to update Endpoints configuration

I am new to GAE and API development. I have been getting this error message from GAE when I try to deploy my code.
10:01 AM Checking if Endpoints configuration has been updated.
10:01 AM Will check again in 60 seconds.
10:02 AM Checking if Endpoints configuration has been updated.
10:02 AM Failed to update Endpoints configuration. There is a /_ah/spi handler configured, but no Google Cloud Endpoints service was found in the app.
10:02 AM See the deployment troubleshooting documentation for more information: https://developers.google.com/appengine/docs/python/endpoints/test_deploy#troubleshooting_a_deployment_failure
10:02 AM Ignoring Endpoints failure and proceeding with update.
Based on the error message, the problem seems to be the application is not calling endpoints.api_server(), which is not exactly the case as you can see in the code below; endpoints.api_server() was called in the last line.
import endpoints
from protorpc import remote, messages
from google.appengine.api import memcache, mail
from google.appengine.ext import ndb
from google.appengine.api import taskqueue
from models import Player, Game, Score, NewGameForm, StringMessage, GameForm, PlayerForm, PlayerForms
from utils import get_by_urlsafe, check_winner
from settings import WEB_CLIENT_ID
EMAIL_SCOPE = endpoints.EMAIL_SCOPE
API_EXPLORER_CLIENT_ID = endpoints.API_EXPLORER_CLIENT_ID
#endpoints.api(name='tic_tac_toe',
version='v1',
allowed_client_ids=[WEB_CLIENT_ID, API_EXPLORER_CLIENT_ID],
scopes=[EMAIL_SCOPE])
class TicTacToeApi(remote.Service):
"""Game API"""
#endpoints.method(request_message=PLAYER_REQUEST,
response_message=StringMessage,
path='player',
name='create_player',
http_method='POST')
def create_player(self, request):
"""Check if user name is unique"""
if Player.get_player_by_name(request.name):
raise endpoints.ConflictException('The name has been taken!')
if not mail.is_email_valid(request.email):
raise endpoints.BadRequestException('Please input a valid email address')
player = Player(name=request.name, email=request.email)
player.put()
return StringMessage(message='Player {} created!'.format(request.name))
#endpoints.method(response_message=PlayerForms,
path='player/ranking',
name='get_player_rankings',
http_method='GET')
def get_player_rankings(self, request):
"""Return rankings for all Players"""
players = Player.query(Player.gamesCompleted > 0).fetch()
players = sorted(players, key=lambda x :x._points, reverse=True)
return PlayerForms(items=[player._copyPlayerToForm for player in players])
api = endpoints.api_server([TicTacToeApi])
Is there something wrong with the app.yaml file?
application: tic-tac-toe-api
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
- url: /_ah/spi/.*
script: api.api
libraries:
- name: webapp2
version: "2.5.2"
- name: endpoints
version: 1.0
- name: pycrypto
version: 2.6
Please feel free to let me know what you think! Thanks a lot

Google App Engine Task Queue error

I'm developing a matchmaking system with gae and python. I was finding a consistent system for automatic matchmaking, and I found the task queue. I implemented a cron job to run every 10 minutes to add a queue. However I'm getting the following error:
When running /queue_generator:
Traceback (most recent call last):
File"/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in Handle
result = handler(dict(self._environ), self._StartResponse)
TypeError: 'module' object is not callable
The code that I have is:
(SessionID is just a db model)
queue_generator.py
import webapp2, time
from main import SessionID
from google.appengine.api import taskqueue
from google.appengine.ext import db
class Game(db.Model):
Users = db.ListProperty(str)
Score = db.IntegerProperty()
Turn = db.StringProperty()
class MainHandler(webapp2.RequestHandler):
def get(self):
taskqueue.add(url='/matchcreator',params={"id":str(time.time())})
class Gamegenerator(webapp2.RequestHandler):
def get(self):
while True:
q = Queue.get()
if len(q.queue) >= 4:
sids = []
for i in range(0,3):
sids.append(q.queue[i])
q.queue.remove(i)
q.put()
return self.response.set_status(204)
def post(self):
while True:
q = Queue.get()
if len(q.queue) >= 4:
sids = []
for i in range(0,3):
sids.append(q.queue[i])
q.queue.remove(i)
q.put()
return self.response.set_status(204)
app = webapp2.WSGIApplication([
('/queue_generator', MainHandler),
("/matchcreator",Gamegenerator)
], debug=True)
Why is this error occuring?
Edit
app.yaml
application: brobbinsgame
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /css
static_dir: css
- url: /home.css
static_files: style.css
upload: style.css
application_readable: true
- url: /register
script: register.app
- url: /logout
script: logout.app
- url: /line
script: line.app
- url: /queue_generator
script: queue_generator
login: admin
- url: /home
script: home.app
- url: /resetsid
script: resetsid.app
login: admin
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: pycrypto
version: "latest"
For every path except "/queue_generator, you have correctly referenced the app object. But for that one path, you reference the module directly. You need to define it in exactly the same way:
- url: /queue_generator
script: queue_generator.app
login: admin
Also notice that there is no way to get to "/matchcreator": "/queue_generator" is the only URL that will be routed to that file. You need to either expose "/matchcreator" in app.yaml as well, or do the more usual thing which is to route all the paths to a main app which imports all the handlers and defines the specific routing there.
This error is occurring because you are calling a Module instead of a Class.. the call should be : Module.Class.Method()

website to deploy in appEngine not showing

Hello: so I am trying to deploy a website to appEngine when I run it with the launcher the log does not have any errors, however when I go to local host the page is blank. I was running this website in python2.5 before with no issues, can you see any errors?
App.yaml
application: myappname
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /(.*\.(gif|png|json|jpg|ico|js|css))
static_files: \1
upload: (.*\.(gif|png|json|jpg|ico|js|css))
- url: .*
script: main.app
- url: /(.*\.json)
mime_type: application/json
static_files: static/\1
upload: static/(.*\.json)
libraries:
- name: webapp2
version: latest
main.py
import webapp2
import os
from google.appengine.ext.webapp2 import util
from google.appengine.ext.webapp2 import template
class MainPage(webapp2.RequestHandler):
def get (self, q):
if q is None:
q = 'index.html'
path = os.path.join (os.path.dirname (__file__), q)
self.response.headers ['Content-Type'] = 'text/html'
self.response.out.write (template.render (path, {}))
app = webapp2.WSGIApplication([('/(.*html)?', MainPage)])
Change the 3rd and 4th lines (you can combine them) to:
from google.appengine.ext.webapp import util, template
That is, webapp, not webapp2.

google app engine wordpress update failure

I have come across a problem with the app.yaml setup for the installation of wordpress in GAE following this guide: https://developers.google.com/appengine/articles/wordpress
Using the guide, I copied the app.yaml (I also used the github project: https://github.com/GoogleCloudPlatform/appengine-php-wordpress-starter-project to check that my copy/paste was ok).
Whilst the test using dev_appserver.py works fine, the upload whinges with the message:
03:08 PM Getting current resource limits.
03:08 PM Scanning files on local disk.
03:08 PM Scanned 500 files.
03:08 PM Scanned 1000 files.
Error 400: --- begin server output ---
Error when loading application configuration:
Unable to assign value '__static__/wordpress/.*\.(htm|html|css|js)$' to attribute 'upload':
Value '__static__/wordpress/.*\.(htm|html|css|js)$' for upload does not match expression '^(?:(?!\^).*(?!\$).)$'
--- end server output ---
I am using the PHP SDK v1.8.9. My app.yaml is as follows:
application: blah-de-blah
version: wp
runtime: php
api_version: 1
handlers:
- url: /(.*\.(htm|html|css|js))$
static_files: wordpress/\1
upload: wordpress/.*\.(htm|html|css|js)$
application_readable: true
- url: /wp-content/(.*\.(ico|jpg|png|gif))$
static_files: wordpress/wp-content/\1
upload: wordpress/wp-content/.*\.(ico|jpg|png|gif)$
application_readable: true
- url: /(.*\.(ico|jpg|png|gif))$
static_files: wordpress/\1
upload: wordpress/.*\.(ico|jpg|png|gif)$
- url: /wp-admin/(.+)
script: wordpress/wp-admin/\1
secure: always
- url: /wp-admin/
script: wordpress/wp-admin/index.php
secure: always
- url: /wp-login.php
script: wordpress/wp-login.php
secure: always
- url: /wp-cron.php
script: wordpress/wp-cron.php
login: admin
- url: /xmlrpc.php
script: wordpress/xmlrpc.php
- url: /wp-(.+).php
script: wordpress/wp-\1.php
- url: /(.+)?/?
script: wordpress/index.php
Something is up with the file type selector regex, but I'm not sure how to fix it. Someone came across it here: Google App Engine and Wordpress set up error - Windows 7 professional but it's still not fixed.
Does anyone have any light to shed on the subject?
Ok - I fixed it. The app.yaml needed modifying.
I think the instructions on the guide are a bit misleading - maybe something is out of date?
Here is my fixed app.yaml:
application: pooper-scooper-117
version: wp
runtime: php
api_version: 1
handlers:
- url: /(.*\.(htm$|html$|css$|js$))
static_files: wordpress/\1
upload: wordpress/.*\.(htm$|html$|css$|js$)
application_readable: true
- url: /wp-content/(.*\.(ico$|jpg$|png$|gif$))
static_files: wordpress/wp-content/\1
upload: wordpress/wp-content/.*\.(ico$|jpg$|png$|gif$)
application_readable: true
- url: /(.*\.(ico$|jpg$|png$|gif$))
static_files: wordpress/\1
upload: wordpress/.*\.(ico$|jpg$|png$|gif$)
- url: /wp-admin/(.+)
script: wordpress/wp-admin/\1
secure: always
- url: /wp-admin/
script: wordpress/wp-admin/index.php
secure: always
- url: /wp-login.php
script: wordpress/wp-login.php
secure: always
- url: /wp-cron.php
script: wordpress/wp-cron.php
login: admin
- url: /xmlrpc.php
script: wordpress/xmlrpc.php
- url: /wp-(.+).php
script: wordpress/wp-\1.php
- url: /(.+)?/?
script: wordpress/index.php
you shouldn't have to modify the app.yaml or submit a pull request(unless it's to change the documentation). Instead you need to get the latest version of the appengine SDK for PHP. As of mid January older versions won't work.

google appengine receive email error

I'm in trouble. I'm playing now for a long time with receiving email in google apps but in my application Logs only get this:
0.1.0.20 - - [13/Jun/2013:08:42:23 -0700] "POST /_ah/mail/contact#myappid.appspotmail.com HTTP/1.1" 200 0 - - "myappid.appspot.com" ms=69 cpu_ms=0 cpm_usd=0.100008 app_engine_release=1.8.1 instance=00c61b117c2fb913155f167711d12979c818fd
My mail handler script schould be this: mailmain.py
import logging
import webapp2
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
from google.appengine.api import mail
class LogSenderHandler(InboundMailHandler):
def receive(self, mail_message):
tobesent = mail_message.subject
logging.info("From: " + mail_message.sender)
logging.info("To:" + mail_message.to)
logging.info("Subject: " + mail_message.subject)
logging.info("Date: " + mail_message.date)
app = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)
and my app.yaml is this:
application: myappid
version: 1
runtime: python27
api_version: 1
threadsafe: no
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /_ah/mail/contact#myappid.appsportmail.com
script: mailmain.py
login: admin
- url: /.*
script: mailmain.py
inbound_services:
- mail
I've tried playing with the script so I have many versions, some ending in this (if this matters) but really nothing works:
def main():
app = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)
run_wsgi_app(application)
if __name__ == "__main__":
main()
I do have a favicon.ico uploaded as well.
Googled the error up for hours and hours and nothing works.
Here on Stackoverflow I've found for similar error message solutions such as correct recieve into receive but this is not the case here. I've copied other solutions as well, also this from GITHUB so I believe this question is not a duplicate.
You mixing up CGI and WSGI. See Python27 getting started.
Docs : https://developers.google.com/appengine/docs/python/gettingstartedpython27/usingwebapp
Yaml update :
application: myappid
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /_ah/mail/contact#myappid.appsportmail.com
script: mailmain.app
login: admin
- url: /.*
script: mailmain.app
inbound_services:
- mail
With WSGI you do not need the run_wsgi_app stuff.
And some background about CGI / WSGI: http://blog.notdot.net/2011/10/Migrating-to-Python-2-7-part-1-Threadsafe

Categories

Resources