1
votes

RELEVANT CODE

Attempt 1:

directory = os.path.dirname (__file__) 
path = os.path.join (directory, 'json', 'gitkit-server-config.json') 
gitkit_instance = gitkitclient.GitkitClient.FromConfigFile (path)

Attempt 2:

directory = os.path.dirname (__file__) 
path = os.path.join (directory, 'gitkit-server-config.json') 
gitkit_instance = gitkitclient.GitkitClient.FromConfigFile (path)

Getting the following error on dev server as well as production server: (Similar error in both attempts)

INFO 2014-08-29 14:34:21,621 module.py:642] default: "GET /_ah/warmup HTTP/1.1" 500 - ERROR 2014-08-29 09:04:26,540 wsgi.py:262]

Traceback (most recent call last):

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in Handle

handler = _config_handle.add_wsgi_middleware(self._LoadHandler())

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 298, in _LoadHandler

handler, path, err = LoadObject(self._handler)

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 84, in LoadObject

obj = __import__(path[0])

File "C:\gaurav\coding\python\myapp\myapp\main_v3.py", line 107, in

gitkit_instance = gitkitclient.GitkitClient.FromConfigFile (path)

File "C:\gaurav\coding\python\myapp\myapp\gitkitclient.py", line 193, in FromConfigFile

json_data = simplejson.load(open(config))

File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\python\stubs.py", line 248, in init

raise IOError(errno.EACCES, 'file not accessible', filename)

IOError: [Errno 13] file not accessible: 'C:\gaurav\coding\python\myapp\myapp\json\gitkit-server-config.json'

INFO 2014-08-29 14:34:26,591 module.py:642] default: "GET /_ah/warmup HTTP/1.1" 500 -

Relevant snippet of app.yaml:

:: 
handlers: 
# For Google Identity Toolkitv3 Oauth2 
- url: /gitkit-server-config\.json 
  static_files: gitkit-server-config.json 
  upload: gitkit-server-config\.json 
- url: /json 
  mime_type: application/json 
  static_dir: json 
::

The file ("gitkit-server-config.json') is copied and kept at both places:

C:\\gaurav\\coding\\python\\myapp\\myapp\\gitkit-server-config.json 
C:\\gaurav\\coding\\python\\myapp\\myapp\\json\\gitkit-server-config.json 

When I put "http://www.myapp.com/gitkit-server-config.json" in web browser, the file gets downloaded.

What am I doing wrong? Appreciate your help.

2
When a file has been declared static (app.yaml), you cannot read it! You have to create a non static copy. - voscausa
@voscausa Thank you so much. The problem is fixed. I modified the relevant part of app.yaml as shown below: - url: /json mime_type: application/json static_dir: json application_readable: true Please provide your suggestion as an answer and I would accept it. - gsinha

2 Answers

3
votes

Do not declare a file static in your app.yaml if you have to read this file using Python Files IO. Make a non static copy or change your app.yaml

UPDATE: you can configure 'application_readable: true' for a static directory in your app.yaml:

- url: /static
  static_dir: static
  application_readable: true
3
votes

All path's should be relative to where your app.yaml lives. So if you directory structure is like

| - myapp/
|   | -app.yaml
|   | - json/
|       | - gitkit-server-config.json

you can try:

path = os.path.join('json', 'gitkit-server-config.json')
gitkit_instance = gitkitclient.GitkitClient.FromConfigFile (path)