Django 1.5 on App Engine - python

I'm having some difficulties setting up Django 1.5 to run via the dev_appserver.py, rather than the manage.py runserver.
The project directory is as such:
env
myproject
manage.py
myproject
init, settings, urls, wsgi (.py)
I've tried to two following ways to get it working with the App Engines appserver:
app.yaml:
application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: django
version: "1.5"
builtins:
- django_wsgi: on
as suggested from this tutorial https://cloud.google.com/appengine/docs/python/cloud-sql/django
It does not produce any error when setting the up the local server, but when I access the given link, I get this error:
RuntimeError: django must be included in the "libraries:" clause of your app.yaml file when using the django_wsgi builtin.
Next I've tried it in a slightly different way.
With app.yaml
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.application
libraries:
- name: django
version: "1.5"
and a main.py as such:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
which produces the following error:
File "C:\Users\Mello\AppEngine\02\myproject\main.py", line 4, in module>
import django.core.handlers.wsgi
ImportError: No module named django.core.handlers.wsgi
Even though if I run
>>>import django.core.handlers.wsgi
>>>
in the same virtual environment, it runs fine.
Anybody has any piece of advice to point me in the right direction to fix this?
Thanks

Related

Unable to set manual scaling on a google app engine service

I am unable to set manual scaling on a google app engine service (Previously called module). Using python on app engine.
app.yaml:
application: xxx-xxxx
version: 2
runtime: python27
module: xxbackend
instance_class: F4
api_version: 1
threadsafe: true
handlers:
- url: /taskcontroller\.py
script: TaskController.app
so on...
libraries:
- name: webapp2
version: latest
- name: numpy
version: "1.6.1"
- name: PIL
version: latest
inbound_services:
- warmup
xxbackend.yaml:
application: xxx-xxxx
version: uno
module: xxbackend
runtime: python27
api_version: 1
instance_class: B4
manual_scaling:
instances: 5
Even though I have specified instance class and manual scaling settings in xxbackend.yaml, the xxbackend instances are still autoscaled. Can someone point out where I am going wrong?
You have the same module: name is both yamls. app.yaml should not specify a module, so it uses the default module. So remove module: xxbackend from app.yaml. Otherwise, you are overriding the expected config.
Then, when you deploy, use a command like:
appcfg.py update app.yaml xxbackend.yaml
That deploys both updated yaml files.

Can't Use Pycrypto in Google App Engine Production

I am successfully using Pycrypto vs. 2.6 in my GAE development environment under Python 2.7. However, deploying it to Google production I see the following error in the logs:
from Crypto.Cipher import _AES ImportError: cannot import name _AES
My App.Yaml:
application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
secure: always
libraries:
- name: webapp2
version: "2.5.2"
- name: pycrypto
version: "2.6"
The Python call in question:
from Crypto.Cipher import AES
Checking Google support documents and they do list Pycrypto 2.6 as supported. I also tried to enter "latest" for the version and received the same error. Again in development GAE on my local machine it works perfectly.
Issue resolved. I had a directory from my Windows installation called "Crypto" in my App Engine project directory. When the app loader loaded the files it also included this directory which conflicted with what Google has loaded in production. Removal of this directory from the local project directory resolved the problem upon the next push to Google.

MissingURLMapping: No URLMap entries found in application configuration

I'm new in GAE development, I've just created a simple API but I'm unable to run my app, because I keep getting the error No URLMap entries found in application configuration.
Here's my app.yaml file
application: gw2
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /_ah/spi/.*
script: main.api_server
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
And here is my main.py file where I've declared the api_server variable
from google.appengine.ext import endpoints
import api
api_server = endpoints.api_server([api.GW2Service])
GW2Service inherits from remote.Service
Edit I'm using command line tools (Ubuntu 12.04)
Where's the mistake?
Thanks in advance. Eric ~H
You start server from the app or command line?
Try using "import endpoints" not from ... import endpoints
In app.yaml set endpoints version to latest.
Move GW2Service to main.py and test if server is ok. The problem might be generated by file name "api".

Getting Started with Python in Google App Engine

I'm just getting started in python with google app engine using the webapp2 framework and jinja2 templating. I can't seem to get my first and very simple script up and running. All I want is for the script to serve the index.html file(located in the same directory).
Here is the app.yaml file:
libraries
- name: webapp2
version: latest
- name: jinja2
version: latest
application: practice
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: practice.application
Here is practice.py:
import os
import webapp2
from jinja2 import Enviroment, FileSystemLoader
loader = jinja2.FileSystemLoader(os.path.dirname(__FILE__)
env = jinja2.Enviroment(loader)
class MainPage(webapp2.RequestHandler):
def get(self):
template = env.get_template('index.html')
self.response.write(template.render())
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
Update:
I am running this locally from the Google app engine launcher.
When I attempt to open the file I receive a server error with the description
The website encountered an error while retrieving http://localhost:9080/. It may be
down for maintenance or configured incorrectly."
Here's why your code won't run:
Your app.yaml is malformed
Enviroment is spelt wrong
Your missing a closing bracket on line 5
You haven't imported the jinja2 library
The variable __FILE__ is undeclared
Here's what I think your code should look like:
app.yaml
application: practice
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
handlers:
- url: /.*
script: practice.application
practice.py
import jinja2
import os
import webapp2
loader = jinja2.FileSystemLoader(os.path.dirname(__file__))
env = jinja2.Environment(loader=loader)
class MainPage(webapp2.RequestHandler):
def get(self):
template = env.get_template('index.html')
self.response.write(template.render())
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
I suggest you do the following to make your life a LOT easier:
download eclipse (I assume you haven't given the syntax errors) -> http://eclipse.org/
complete the tutorial -> https://developers.google.com/appengine/docs/python/gettingstartedpython27/introduction
read the docs -> https://developers.google.com/appengine/docs/python/
Hope this helps get you on your way.
Happy coding :)
In webapp2 you should use app instead of application, so last line should look like this:
app = webapp2.WSGIApplication([('/', MainPage),], debug=True)

Error uploading application Python Google App Engine

I have been trying to upload python Google app engine folder using windows command prompt. I have the app.yaml as well as a python file in the folder. But when I pass the following command in the Command Prompt:
appcfg.py --oauth2 update C:/Path/to/the/folder
I get this error.
appcfg.py: error: Directory does not contain an Project.yaml configuration file.
Where am I wrong and how should I proceed?
This is my app.yaml file:
application: myappid
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: sampleapp.app
libraries:
- name: lxml
version: "latest"
Check your shell syntax. I had this error message also, by not referencing the right project folder. Note the ending slash:
appcfg.py --oauth2 update C:/Path/to/the/folder/

Categories

Resources