Tuesday, November 9, 2010

Unity Security and Google App Engine (Python)

I'm relatively new to programming with both Unity and Google App Engine and Python.  I've been playing with them for not even a month now, and ran into a nasty situation today.

Namely, attempting to read any text from a website in Unity doesn't work, unless that website also serves a crossdomain.xml file.  This is explained in some detail here:

http://unity3d.com/support/documentation/Manual/Security%20Sandbox.html

Great!  I'll just add that crossdomain.xml file, and those runtime errors will go away right?  No.  And here I show my flying blind syndrome - I don't know all the ins and outs of app engine yet.  But if you dig deep enough, this is explained with sufficient searching.

The reason it doesn't work to just place the crossdomain.xml file in the project directory, is that the app.yaml file has to be configured to stop expecting every request to the root directory to be handled by the <whatever>.py file, which is what you get when you run the Python tutorial from Google App Engine:

http://code.google.com/appengine/docs/python/gettingstarted/

You'll wind up with an app.yaml file that looks like this:


application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: /.*
  script: helloworld.py


And they explain it actually very clearly - but for some reason it just didn't sink in:

"Every request to a URL whose path matches the regular expression /.* (all URLs) should be handled by the helloworld.py script."

To get App Engine to serve the crossdomain.xml file, change hte app.yaml file to look like this instead:

application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: /crossdomain.xml
  static_files: static/crossdomain.xml
  upload: static/crossdomain.xml

- url: /.*
  script: helloworld.py

Then place the crossdomain.xml file in a subdirectory "static" and that's it.  Unity can now use the WWW class to read text from an app engine website.


No comments:

Post a Comment