Google App Engine Setup Revised

Installation:

Setting up your project:

  1. Create a directory
  2. Create two files main.py and app.yaml
    app.yaml:

    application: mytestapp
    version: 1
    runtime: python27
    threadsafe: true
    api_version: 1
    default_expiration: "5d 12h"

    handlers:
    - url: /.*
    script: main.app

    main.py:

    import webapp2

    class Index(webapp2.RequestHandler):
    def get(self):
    self.response.out.write('hello world!')

    mappings = [('/', 'main.Index')]
    app = webapp2.WSGIApplication(mappings)

  3. Launch VS. File->New->Project->Python Templates->From Existing Python Code
  4. Add above two files to the project
  5. Alt->ENTER->General. Set Startup File to C:\Program Files (x86)\Google\google_appengine\dev_appserver.py
  6. Alt->ENTER->Debug. Set Script Arguments to directory in step 1
  7. F5
  8. You will get a ZipImportError. Fix it using this link: http://pytools.codeplex.com/discussions/265255
  9. Verify this output in python shell:
    INFO 2013-03-10 15:07:15,349 appcfg.py:618] Checking for updates to the SDK.

    INFO 2013-03-10 15:07:16,717 appcfg.py:636] The SDK is up to date.
    WARNING 2013-03-10 15:07:16,720 dev_appserver.py:3578] The datastore file stub
    is deprecated, and
    will stop being the default in a future release.
    Append the –use_sqlite flag to use the new SQLite stub.

    You can port your existing data using the –port_sqlite_data flag or
    purge your previous test data with –clear_datastore.

    WARNING 2013-03-10 15:07:16,779 simple_search_stub.py:975] Could not read searc
    h indexes from c:\users\me\appdata\local\temp\dev_appserver.searchindexes
    INFO 2013-03-10 15:07:17,049 dev_appserver_multiprocess.py:656] Running appl
    ication dev~mytestapp on port 8080: http://localhost:8080
    INFO 2013-03-10 15:07:17,052 dev_appserver_multiprocess.py:658] Admin consol
    e is available at: http://localhost:8080/_ah/admin

  10. Open web browser, navigate to http://localhost:8080/
  11. Verify web page that says hello world!
  12. Now to break above code (just for testing), simply change
    mappings = [('/', 'main.Index')]
    to
    mappings = [('/', 'Index')]

    Now if you refresh the webpage, you will see:
    500 Internal Server Error

    The server has either erred or is incapable of performing the requested operation.

    Python shell will show:
    ERROR 2013-03-10 15:10:17,605 webapp2.py:1552] import_string() failed for ‘In
    dex’. Possible reasons are:

    – missing __init__.py in a package;
    – package or module path not included in sys.path;
    – duplicated package or module name taking precedence in sys.path;
    – missing module, class, function or variable;

    Original exception:

    ImportError: No module named Index

    Debugged import:

    – ‘Index’ not found.
    Traceback (most recent call last):
    File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2
    .py”, line 1535, in __call__
    rv = self.handle_exception(request, response, e)
    File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2
    .py”, line 1529, in __call__
    rv = self.router.dispatch(request, response)
    File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2
    .py”, line 1272, in default_dispatcher
    self.handlers[handler] = handler = import_string(handler)
    File “C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2
    .py”, line 1852, in import_string
    return __import__(import_name)
    ImportStringError: import_string() failed for ‘Index’. Possible reasons are:

    – missing __init__.py in a package;
    – package or module path not included in sys.path;
    – duplicated package or module name taking precedence in sys.path;
    – missing module, class, function or variable;

    Original exception:

    ImportError: No module named Index

    Debugged import:

    – ‘Index’ not found.
    INFO 2013-03-10 15:10:17,674 dev_appserver.py:3104] “GET / HTTP/1.1” 500 –

This entry was posted in Software. Bookmark the permalink.

Leave a comment