I have downaloded and installed Python 2.7.6 in my Windows and I have also installed the latest version of the GAE SDK for Windows as well.
I have the following configurations on my GAE:
I am running an Hello World project with the following files:
Main.py
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world!')
app = webapp2.WSGIApplication([('/', MainHandler)], debug=True)
app.yaml
application: HelloWorld
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.2"
However, When I click the button Run, in order to runt he project, I get the following errors in the LOG output:
2013-12-04 14:51:49 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8000', 'D:\\Users\\pedro\\Desktop\\HelloWorld']"
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 197, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in _run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 872, in <module>
main()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 865, in main
dev_server.start(options)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 657, in start
options.yaml_files)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 549, in __init__
module_configuration = ModuleConfiguration(yaml_path)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 82, in __init__
self._yaml_path)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 266, in _parse_configuration
return appinfo_includes.ParseAndReturnIncludePaths(f)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\appinfo_includes.py", line 63, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\appinfo.py", line 1756, in LoadSingleAppInfo
listener.Parse(app_info)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\yaml_listener.py", line 226, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\yaml_listener.py", line 177, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: Unable to assign value 'HelloWorld' to attribute 'application':
Value 'HelloWorld' for application does not match expression '^(?:(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{0,99}[a-z\d])$'
in "D:\Users\pedro\Desktop\HelloWorld\app.yaml", line 1, column 14
2013-12-04 14:51:50 (Process exited with code 1)
Thus I have the following questoins:
I have created this project by going to File -> New application, but apparently my auto-generated app.yaml file is incorrect. What am I doing wrong?
I have tried to use Python 3.3 first, but it was not working. GAE only works with Python 2.7 right? I am doing everythign correctly right?
When I click the Browse button I get the error saying that no browser is specified. How do I fix that?
Thanks for any help if possible :S
According to the regex that isn't matching, the app name needs to be lowercase:
>>> regex = r'^(?:(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{0,99}[a-z\d])$'
>>> print(re.match(regex, 'HelloWorld'))
None
>>> print(re.match(regex, 'helloworld'))
<_sre.SRE_Match object at 0x13ac308>
Your application identifier('HelloWorld') is invalid. You should use the one you created in the Administration Console according to the GAE doc.
The ID will be the subdomain of your GAE application when it deployed in appspot.com. That's why the app id should match the regex r'^(?:(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{0,99}[a-z\d])$'.
Related
I am trying to run a simple python script on Google App Engine. How do I install the Google Analytics API library?
Library: https://developers.google.com/api-client-library/python/apis/analytics/v3
Instructions: https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring
I've tried everything and can't get this to run, even though it works on my pc. What I have right now is:
The python scripts in the root folder,
In the /lib folder I copied the folders that were installed from my PC (/googleapiclient and /google_api_python_client-1.4.0-py2.7.egg-info)
And I have appengine_config.py in /lib folder which contains:
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
vendor.add('google-api-client')
app.yaml file:
application: psyched-cab-861
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: hello_analytics_api_v3.app
Traceback:
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])
ImportError: No module named helloworld
New Log:
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/api/lib_config.py", line 354, in __getattr__
self._update_configs()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 290, in _update_configs
self._registry.initialize()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 165, in initialize
import_func(self._modname)
File "/base/data/home/apps/s~just-terminus-94303/1.384249106864280829/appengine_config.py", line 5, in <module>
vendor.add('google-api-python-client')
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/vendor/__init__.py", line 44, in add
'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access google-api-python-client: No such virtualenv or site directory
I tried editing the appengine_config.py file to
vendor.add('googleapiclient') #The name of the file
I edit it in GAE, and click commit, it saves, but I get the same error as above with the vendor.add('google-api-python-client') error. Why is the file not updating?
As the docs say: put the appengine_config.py in your root folder of the application (and not in the /lib folder).
By the way, the name of the library is google-api-python-client and not google-api-client.
Then you have to install google-python-api-client in your /lib folder:
$ pip install -t lib google-api-python-client
A few months ago I was working on a test GAE app. I was able to start the launcher and open the browser both on the app port and on the SDK Console port, and they both were working well.
Then I installed CherryPy, I created a CherryPy app, and I was able to browse to the app.
Today I restarted the GAE launcher. When I browse to my app page everything works well, while browsing to the SDK Console it shows the correct content, but doesn't show the static files.
The log mentions CherryPy.
Is the CherryPy I installed conflicting with GAE?
Does GAE use CherryPy (and my installation has nothing to do with it)?
How do I fix it?
For example when I browse to http://localhost:8002/assets/common.css (which is the css used by the SDK Console) I get the following log:
ERROR 2014-08-19 20:23:08,052 webapp2.py:1553] WSGI response header value u'text/css' is not of type str.
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1547, in __call__
return response(environ, start_response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webob-1.2.3\webob\response.py", line 1021, in __call__
start_response(self.status, headerlist)
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 2155, in start_response
raise TypeError("WSGI response header value %r is not of type str." % v)
TypeError: WSGI response header value u'text/css' is not of type str.
AssertionError('WSGI start_response called a second time with no exc_info.',)
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 1302, in communicate
req.respond()
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 831, in respond
self.server.gateway(self).respond()
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 2115, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\wsgi_server.py", line 266, in __call__
return app(environ, start_response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.1\webapp2.py", line 1549, in __call__
return self._internal_error(e)(environ, start_response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webob-1.2.3\webob\response.py", line 1021, in __call__
start_response(self.status, headerlist)
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 2137, in start_response
raise AssertionError("WSGI start_response called a second "
AssertionError: WSGI start_response called a second time with no exc_info.
There is a bug in the GAE Windows static file handling. It has been documented here:
Google App Engine: Won't serve static assets with below error:
Reported to be fixed by updating from Python 2.7.7 to 2.7.8. Otherwise, you will want to explicitly specify the MIME types for your static files in app.yaml, as shown on that linked page.
I am using Ubuntu Server 13.10 and Python 2.7.
I would like to have two versions of my App Engine application: admin and the default version. I have defined these two versions. Currently, this is my app.yaml file:
application: application-id
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /
script: python.MainPage.application
- url: /test.*
script: gaeunit.application
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
version: admin
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /.*
script: python.MainPage.application
login: admin
auth_fail_action: unauthorized
- url: /test.*
script: python.MainPage.appication
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
When I deploy this code to App Engine, it works as expected. However, If I attempt to run it using dev_appserver.py found in the Google Cloud SDK, it fails with this traceback:
Traceback (most recent call last):
File "/home/katie/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 82, in <module>
_run_file(__file__, globals())
File "/home/katie/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 78, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 902, in <module>
main()
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 895, in main
dev_server.start(options)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 672, in start
options.yaml_files)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 556, in __init__
module_configuration = ModuleConfiguration(yaml_path)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 82, in __init__
self._yaml_path)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 272, in _parse_configuration
return appinfo_includes.ParseAndReturnIncludePaths(f)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo_includes.py", line 63, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo.py", line 1826, in LoadSingleAppInfo
listener.Parse(app_info)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 226, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 177, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: Duplicate attribute 'version'.
in "aerobic-arcade-514/default/app.yaml", line 24, column 10
You can launch two different dev app servers on two different ports, just override the default port with the --port= parameter, however you will need to have two app.yaml files separated, not using the same file as you did. When you run dev_appserver.py, use the config file as the final argument instead of the directory (which defaults to app.yaml).
For example:
dev_appserver.py --port=8888 app_one.yaml
dev_appserver.py --port=9999 app_two.yaml
After your testing and before deploying, make sure you leave the definitive file with the name app.yaml; otherwise, you won't be able to complete the process.
I don't know what changed, but suddenly none of my Python App Engine projects will start on my PC. They start on my MacBook just fine, so there's something about the installation on my PC that's messed up. I've tried going back to 1.8.8, but that doesn't work. I've also tried using a fresh Python installation, but that didn't work. I've even tried using port 8080 (I usually use port 80, as I run the app launcher as admin).
This is what shows up in the error log when I click start on one of my projects:
2014-02-05 10:42:24 Running command: "['c:\\users\\jonathan\\appdata\\local\\enthought\\canopy\\user\\scripts\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=80', '--admin_port=8000', 'C:\\Users\\jonathan\\My Repositories\\my-project']"
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 197, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in _run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 32, in <module>
from google.appengine.tools.devappserver2.admin import admin_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\admin_server.py", line 29, in <module>
from google.appengine.tools.devappserver2.admin import console
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\console.py", line 22, in <module>
from google.appengine.tools.devappserver2 import module
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\module.py", line 69, in <module>
from google.appengine.tools.devappserver2 import wsgi_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\wsgi_server.py", line 31, in <module>
from cherrypy import wsgiserver
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\__init__.py", line 278, in <module>
_pydoc._builtin_resolve = _pydoc.resolve
AttributeError: 'module' object has no attribute 'resolve'
2014-02-05 10:42:32 (Process exited with code 1)
Also, I'm using Windows 7 x64. My original installation of Python is from Enthought x64, but I did try using the basic x64 Python as well. As mentioned, I downgraded from 1.8.9 to 1.8.8, to no avail.
From a quick Google search, other users are suggesting it's a bug in pyvenv. Since not very many people are still using CherryPy, and it seems to only manifest itself in whatever CherryPy is doing there, that's probably it.
Bug the gist is that somewhere, only on Windows, you have a pydoc.py file which is being imported instead of the standard library's pydoc file.
So, find the offending pydoc.py file in your import path, and rename it. You can most likely find it by doing something like this:
import pydoc
print pydoc.__file__
I want to access a file in my computer from a google app engine application. If I put the file in the src folder of the application there is no problem but I need this file to be out of that folder.
When I try to access this file I get the next error:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 712, in __call__
handler.post(*groups)
File "C:\Users\path\Documents\path\oauth2client\appengine.py", line 469, in check_oauth
return method(request_handler, *args, **kwargs)
File "C:\Users\path\Documents\path\myapp.py", line 88, in post
filename=open('C:/Users/path_to_file/Documento 1.docx','r')
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 635, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: 'C:/Users/path_to_file/Documento 1.docx'
I have read that if a file is defined as static in app.yaml can't be accessible from GAE. This is my app.yaml. I can't figure out if there is something wrong:
application: myapp
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: myapp.py
And this is the part of the application that tries to access the file:
filename='C:/Users/path_to_file/Documento 1.docx'
media_body = MediaFileUpload(filename,resumable=True)
Does someone know why do I get the "file not accessible" error?
Thanks!
Put the file in the same directory as the rest of your applications files (i.e. where the app.yaml is).
All the files you want your application to access have to be in the same place, under your main application directory.
GAE can't access arbitrary files somewhere on your computer, just like it cannot access files saved "somewhere" else when deployed.
filename='myfile.doc'
That's assuming it's in the 'root' (same as app.yaml).
In your app.yaml file you need to make the file visible to your app:
handlers:
- url: /<location to your data files>
script: <your app name>.app
For example in my app.yaml file it looks like this
- url: /data
script: main.app