How to migrate my app.yaml to 2.7? - python

I'm migrating my gae app to python 2.7. This is my new app.yaml:
application: webfaze
version: main
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /mapreduce(/.*)?
script: mapreduce/main.application
- url: /(.*\.(html|css|js|gif|jpg|png|ico|swf))
static_files: static/\1
upload: static/.*
expiration: "1d"
- url: .*
script: main.application
- url: /task/.*
script: main.application
login: admin
But I get this error message:
Error parsing yaml file:
Invalid object:
threadsafe cannot be enabled with CGI handler: mapreduce/main.application
in "webfaze/app.yaml", line 22, column 1
Can you tell me how to resolve the error?

Checking the source code, it looks that you need to define your handlers' path without any slash:
if (handler.script and (handler.script.endswith('.py') or
'/' in handler.script)):
raise appinfo_errors.ThreadsafeWithCgiHandler(
'threadsafe cannot be enabled with CGI handler: %s' %
handler.script)
Move application.py to the root of your project and modify the handler's path accordingly.

Change:
- url: /mapreduce(/.*)?
script: mapreduce/main.application
To:
- url: /mapreduce(/.*)?
script: mapreduce.main.application
You may also need to add an __init__.py to the 'mapreduce' folder if one doesn't exist there already. That will make the python interpret the folder as a module.

Related

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.

GAE app.yaml Script Handling for scripts in subdirectories (python)

I am setting up a new GAE project, and I can't get my scripts in sub-directories to work.
EDIT: If I go to localhost:8080/testing_desc.html I don't any errors, just a blank page (view-source is blank, too). Scripts in my root dir work normally. There is a __init__.py in both the root and sub-dir.
Python script example ("/testing/testing_desc.py"):
import webapp2 as webapp
class DescTstPage(webapp.RequestHandler):
def get(self):
html = 'This should work.'
self.response.out.write(html)
app = webapp.WSGIApplication([('/.*', DescTstPage)], debug=True)
app.yaml:
application: blah
version: blah
runtime: python27
api_version: 1
default_expiration: "5d 12h"
threadsafe: false
libraries:
- name: webapp2
version: latest
handlers:
- url: / <-- This one works
script: main.app
- url: /index.html <-- This does NOT work (??)
script: main.app
- url: /(.*?)_desc.html <-- Also does NOT work
script: \1/\1_desc.app
#file not found
- url: /.*
script: file_not_found.app
I have also tried a simpler version of the yaml:
-url: /testing_desc.html
script: /testing/testing_desc.app
When you use WSGI Pyhon27 this will work. Use a dot for the seperator :
-url: /testing_desc.html
script: /testing.testing_desc.app
You are passing a list of routes to your WSGIApplicaiton call. Those routes must match whatever URL is being handled.
('/', DescTstPage) just matches the '/' URL to your handler. /.* matches all routes.
What routes are you setting in testing/testing_desc.app? They must match /testing_desc.html.
To get my scripts working in sub-dir, I changed the app.yaml and /testing/testing_desc.py to this:
app.yaml:
- url: /testing.html
script: testing/testing_desc.py
/testing/testing_desc.py:
app = webapp.WSGIApplication([('/.*', DescTstPage),], debug=True)
def main():
run_wsgi_app(app)
if __name__ == '__main__':
main()
ATM I do not understand how to make the routing work with sub-dir, so I will use this.
The answer is here:
How can i use script in sub folders on gae?
Its not explicitly stated, but in the answer you must change /foo/ to /foo in the WSGIApplication call, which maps to www.bar.com/foo. If you want to map to www.bar.com/foo.html you need to change /foo to /foo.* in the WSGIApplication call AND the url handler in app.yaml to - url: /foo\.html

Make a GET request to a local file in Google App Engine using Ajax

I'd like to run a function server side using a Python file on my Google App Engine application with this Ajax call.
function test(){
request = $.ajax({
url: "test.py?some_vars...",
type: "get",
});
request.done(function (response, textStatus, jqXHR){
console.log(response);
});
}
When I run test() the console logs a 404 error, "test.py not found". I've also tried "localhost:8080/test.py" locally and "http://APP.appspot.com/test.py" on the actual server.
I get a response when I try an external file like "http://graph.facebook.com/steve", but I can't get anything from local files.
Here is my app.yaml
application: APP
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /images
static_dir: images
- url: /js
static_dir: js
- url: /css
static_dir: css
- url: /.*
script: apprtc.app
secure: always
- url: /python
script: test.app
inbound_services:
- channel_presence
libraries:
- name: jinja2
version: latest
Thanks for reading
You need to set up a handler in app.yaml that maps to your test.py.
You'll need a route that looks something like...
- url: /test.py
script: test.app

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

Python App Engine : use app.yaml to control url handler

When I control different type of pages, I move my code to another python file. But this way has disadvantage : each time I want to change url hander, I must comback to main.py to config bottom lines about url handler. for example :
app = webapp2.WSGIApplication([('/', MainPage),
('/thanks',ThanksHandler),
('/unit2/signup',Signup),
('/unit2/successful', LoginSuccess)], debug=True)
I try to config handler in app.yaml to prevent dis advantage.
I add file blog.py in same directory and in this file, I have Blog class. And here is my blog.py file:
class Blog(BaseHandler):
def get(self):
self.response.out.write("Hello")
app = webapp2.WSGIApplication([('/blog', Blog)], debug=True)
Here is original file:
> handlers:
> - url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico
- url: /.* script: main.app
and this new file app.yaml:
handlers:
- url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico
- url: /blog/.* script: blog.app
- url: /.* script: main.app
But when I goto: localhost:port/blog : 404: resource not found.
Please help me.
Thanks :)
The /blog/.* url specification from the yaml file does not match the url specification from the blog.py file (/blog). In particular the fact that /blog/.* requires the url to have a slash after blog. If for example you use just /blog in both places it will work. Or you can use /blog/.* in both places.
The url specifiers are matched in the order in which they appear in the yaml file therefore in this particular case /blog/.* will not match on /blog but will match on the last (catch all really) /.* specifier and therefore main.py handler will be loaded and fail to match (no pattern in the call WSGIApplication constructor inside main.py).
Hope this helps.
-Silviu

Categories

Resources