Static files application_readable usage
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Intrigue Looping
--
Chapters
00:00 Question
02:09 Accepted answer (Score 17)
06:23 Thank you
--
Full question
https://stackoverflow.com/questions/1653...
Accepted answer links:
http://code.google.com/p/googleappengine...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #googleappengine
#avk47
ACCEPTED ANSWER
Score 17
Overview
It's somewhat difficult to reason about what exactly is going on on your system, but I can tell you what works on mine. We can speculate all day about what could be wrong, but implementing something that works and working backwards is usually more productive than guessing; it could be anything.
If I were to guess, I'd say that the problem is:
- Incorrect handler order
- Screwed up python paths
- Screwed up python versions
- Using a janky old SDK
- Underpants gnomes
If, instead of guessing, you implement the project I've outlined below, it should be pretty simple to reason backward and find out why it's not working for you. If this project doesn't work, you've got some work to do. The problem's really nasty (and I don't want to help you fix it). If it does work, you're in luck, since you're 5 or 10 minutes away from having the rest of your code working too!
Using the latest python appengine SDK from http://code.google.com/p/googleappengine/downloads/list:
google_appengine_1.8.0.zip
71b5f3ee06dce0a7d6af32d65ae27272eac038cb
Project files and their contents:
Directory Setup:
.
├── app.py
├── app.pyc
├── app.yaml
└── static
└── hi.txt
app.py:
import webapp2
import os
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!\n\n')
path = os.path.join(os.path.split(__file__)[0], 'static/hi.txt')
self.response.out.write(open(path).readlines()[0])
application = webapp2.WSGIApplication([('/.*', MainPage)])
app.pyc is the (automatically) compiled version of this file.
app.yaml:
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /static
static_dir: static
application_readable: true
- url: /.*
script: app.application
static/hi.txt:
Ezra can see this text fine; I'm not sure why you can't... Hi!
What happens:
Start the webserver from the project root:
dev_appserver.py --port 80 .
You might have to use a different port number; it's no big deal. Just adjust the instructions that follow for the one you choose.
Visiting http://localhost/ in the browser:
Http response:
INFO 2013-05-14 09:45:57,372 server.py:585] default: "GET / HTTP/1.1" 200 85
Browser output:
Hello, webapp World!
Ezra can see this text fine; I'm not sure why you can't... Hi!
Visiting http://localhost/static/hi.txt in the browser:
Http response:
INFO 2013-05-14 09:48:42,785 server.py:585] default: "GET /static/hi.txt HTTP/1.1" 200 63
Browser output:
Ezra can see this text fine; I'm not sure why you can't... Hi!
Breaking it:
If I remove the application_readable: true line from app.yaml:
Visiting http://localhost/ in the browser:
Http Response:
ERROR 2013-05-14 09:51:13,290 webapp2.py:1528] [Errno 13] file not accessible: '.../static/hi.txt'
Browser output:
500 Internal Server Error
The server has either erred or is incapable of performing the requested operation.
What to do next:
Hopefully you can work backwards from this example. If it doesn't work for you, you're doomed. Enjoy spending a sunny mid-May afternoon trawling through paths and trying to (re/un)install things to get this frickin' thing going. The list at the top is a list of I'd try, without knowing any specifics and having ruled out programming error. Good luck!