Google App Engine Task Queue error - python

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()

Related

Google App Engine - Endpoints Failure

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.

GAE/Python ImportError only on the deployed version

Hi everyone I'm struggling with AppEngine, I made my webapp on the development server, everything worked fine but once I deploy it gives me an ImportError.
My main directory is as follows:
-/
-Several
-Folders
-...
*admin.py
*app.yaml
*db_objects.py
*index.yaml
*img_getter.py
*keys.py
*main.py
*main_handler.py
My app.yaml file:
application: myapplication (this is not the real name)
version: 1
runtime: python27
api_version: 1
threadsafe: yes
default_expiration: "7d"
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /css
static_dir: css
- url: /img
static_dir: img
- url: /images
static_dir: images
- url: /js
static_dir: js
- url: /admin.*
script: admin.app
login: admin
- url: /checkout.*
script: main.app
login: required
- url: /confirm.*
script: main.app
login: required
- url: /changeinfo.*
script: main.app
login: required
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
When I go to myaddress.appengine.com/admin it gives me this error:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~myapplication/1.383371027775991819/admin.py", line 7, in <module>
import img_getter
ImportError: No module named img_getter
This is the beginning of admin.py:
#coding=utf-8
import webapp2
from main_handler import Handler
import db_objects
from google.appengine.ext import db
import img_getter
from google.appengine.api import memcache
import keys
from datetime import date
class MainHandler(Handler):
def get(self):
self.redirect("/admin/noticias")
...
And this is the beginning of the img_getter.py file:
import gdata.photos.service
import gdata.media
import gdata.geo
def foo(variable):
...
def bar(variable):
...
#functions to get images from the google picassa service
The thing is I've been developing this webapp on the developer server and it's been working like a charm, I've even cleared the datastore and tried on several computers and it's still working, but when I try to test it on Google servers I'm finding this error.
I haven't define any reference on the app.yaml file as I think it's not necesary because it's not a library depending from google python API, am I wrong?
Does anybody know what the problem is?
Thank you very much :)
You might need to import it as a package.
https://docs.python.org/2/tutorial/modules.html#packages
Create a folder called 'test' (or whatever you want) for img_getter.py and put it in there
Add a file called __init__.py and save it in the folder you put img getting in. This file can be empty
call the import as
import test.img_getter
Reference
How to import python script files in folders on Google App Engine?
Cheers and good luck!

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 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

Getting broken link error whle Using App Engine service accounts

I'm following this tutorial
https://developers.google.com/bigquery/docs/authorization#service-accounts-appengine
Here is my main.py code
import httplib2
from apiclient.discovery import build
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import AppAssertionCredentials
# BigQuery API Settings
SCOPE = 'https://www.googleapis.com/auth/bigquery'
PROJECT_NUMBER = 'XXXXXXXXXX' # REPLACE WITH YOUR Project ID
# Create a new API service for interacting with BigQuery
credentials = AppAssertionCredentials(scope=SCOPE)
http = credentials.authorize(httplib2.Http())
bigquery_service = build('bigquery', 'v2', http=http)
class ListDatasets(webapp.RequestHandler):
def get(self):
datasets = bigquery_service.datasets()
listReply = datasets.list(projectId=PROJECT_NUMBER).execute()
self.response.out.write('Dataset list:')
self.response.out.write(listReply)
application = webapp.WSGIApplication(
[('/listdatasets(.*)', ListDatasets)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Here is my app.yaml file code
application: bigquerymashup
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.py
And yes i have added app engine service account name in google api console Team tab with can edit permissions.
When upload the app and try to access the link it says
Oops! This link appears to be broken.
Ealier i ran this locally and tried to access it using link localhost:8080.Then i thought may be running locally might be giving the error so i uploaded my code to
http://bigquerymashup.appspot.com/
but still its giving error.
EDIT:
Updated App.yaml
application: bigquerymashup
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.py
- url: /listdatasets
script: main.py
But getting another error
Traceback (most recent call last): File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp2‌​5.py", line 710, in call handler.get(*groups) TypeError: get() takes exactly 1 argument (2 given)
You need to define a Script Handlers that matches the URL you are trying to locate.
Try: http://[your_app_id_here].appspot.com/listdatasets
Read more about handlers here.

Categories

Resources