python - Static files application_readable usage -


i've been trying understand how application_readable static url handler field works. i'm using sdk version 1.7.7 , i've set true on application in dev environment, can't seem read file:

# app.yaml  - url: /test   static_dir: application/static/test   application_readable: true  # app.py  path = os.path.join(os.path.split(__file__)[0], 'static/test/test.png') self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) self.response.out.write("\n") path = '/application/static/test/test.png' self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) self.response.out.write("\n") path = 'application/static/test/test.png' self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) self.response.out.write("\n") path = '/static/test/test.png' self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) self.response.out.write("\n") path = 'static/test/test.png' self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) self.response.out.write("\n") path = '/test/test.png' self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) self.response.out.write("\n") path = 'test/test.png' self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) self.response.out.write("\n") path = '/test.png' self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) self.response.out.write("\n") path = 'test.png' self.response.out.write('looking %s...' % path) self.response.out.write(os.path.exists(path)) 

but none of work:

looking /vagrant/test/application/static/test/test.png...false looking /application/static/test/test.png...false looking application/static/test/test.png...false looking /static/test/test.png...false looking static/test/test.png...false looking /test/test.png...false looking test/test.png...false looking /test.png...false looking test.png...false 

though file exists:

vagrant@precise64:/vagrant/kissyface$ ls -l /vagrant/test/application/static/test/test.png -rwxrwxrwx 1 vagrant vagrant 9920 may  3 18:13 /vagrant/test/application/static/test/test.png 

can tell me i'm doing wrong? haven't been able find documentation or example code beyond brief description in statis url handler docs , mention in appengine sdk 1.7.6 changelog. there utility class provides access these files, or misinterpreting application_readable supposed do?

overview

it's difficult reason exactly going on on system, can tell works on mine. can speculate day wrong, implementing works , working backwards more productive guessing; anything.

if guess, i'd problem is:

  1. incorrect handler order
  2. screwed python paths
  3. screwed python versions
  4. using janky old sdk
  5. underpants gnomes

if, instead of guessing, implement project i've outlined below, should pretty simple reason backward , find out why it's not working you. if project doesn't work, you've got work do. problem's nasty (and don't want fix it). if work, you're in luck, since you're 5 or 10 minutes away having rest of code working too!

using latest python appengine sdk http://code.google.com/p/googleappengine/downloads/list:

google_appengine_1.8.0.zip 71b5f3ee06dce0a7d6af32d65ae27272eac038cb 

project files , 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 (automatically) compiled version of 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 text fine; i'm not sure why can't... hi! 

what happens:

start webserver project root:

 dev_appserver.py --port 80 . 

you might have use different port number; it's no big deal. adjust instructions follow 1 choose.

visiting http://localhost/ in 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 text fine; i'm not sure why can't... hi!

visiting http://localhost/static/hi.txt in 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 text fine; i'm not sure why can't... hi!

breaking it:

if remove application_readable: true line app.yaml:

visiting http://localhost/ in 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 incapable of performing requested operation.

what next:

hopefully can work backwards example. if doesn't work you, you're doomed. enjoy spending sunny mid-may afternoon trawling through paths , trying (re/un)install things frickin' thing going. list @ top list of i'd try, without knowing specifics , having ruled out programming error. luck!


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -