IOError: [Errno 13]文件在Google AppEngine 1.6.1中不可访问。

11
也许这是一个bug,但我还是在这里发布了。我在本地AppEngine测试服务器上遇到了以下问题:
WARNING  2012-01-10 06:08:40,336 rdbms_mysqldb.py:90] The rdbms API is not available because the MySQLdb library could not be loaded.
INFO     2012-01-10 06:08:40,470 appengine_rpc.py:159] Server: appengine.google.com
INFO     2012-01-10 06:08:40,474 appcfg.py:561] Checking for updates to the SDK.
INFO     2012-01-10 06:08:40,990 appcfg.py:574] Update check failed: HTTP Error 404: Not Found
WARNING  2012-01-10 06:08:47,643 dev_appserver.py:3344] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO     2012-01-10 06:08:47,654 dev_appserver_multiprocess.py:638] Running application dev~project_name on port 8080: http://localhost:8080
INFO     2012-01-10 06:08:47,654 dev_appserver_multiprocess.py:640] Admin console is available at: http://localhost:8080/_ah/admin
INFO     2012-01-10 06:09:14,989 dev_appserver_index.py:338] Created 2 and deleted 0 index(es); total 2
WARNING  2012-01-10 06:09:15,480 py_zipimport.py:139] Can't open zipfile /Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg: IOError: [Errno 13] file not accessible: '/Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg'
ERROR    2012-01-10 06:09:16,927 bottle.py:746] Traceback (most recent call last):
  File "/Users/ca/Dropbox/Perso/projects/project_name/Source/project_name/lib/bottle.py", line 735, in _handle
    return route.call(**args)
  File "/Users/ca/Dropbox/Perso/projects/project_name/Source/project_name/lib/bottle.py", line 1451, in wrapper
    rv = callback(*a, **ka)
  File "/Users/ca/Dropbox/Perso/projects/project_name/Source/project_name/tools.py", line 41, in render_to_response
    template = jinja_env.get_template(template_name)
  File "/Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/jinja2/environment.py", line 719, in get_template
  File "/Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/jinja2/environment.py", line 693, in _load_template
  File "/Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/jinja2/loaders.py", line 115, in load
  File "/Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/jinja2/loaders.py", line 165, in get_source
  File "/Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/jinja2/utils.py", line 224, in open_if_exists
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 578, in __init__
    raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/Users/ca/Dropbox/Perso/Projects/project_name/Source/project_name/templates/tools_list.html'

INFO     2012-01-10 06:09:16,962 dev_appserver.py:2832] "GET / HTTP/1.1" 500 -
INFO     2012-01-10 06:09:16,974 dev_appserver_index.py:255] Updating /Users/ca/Dropbox/Perso/projects/project_name/Source/project_name/index.yaml
WARNING  2012-01-10 06:11:36,153 py_zipimport.py:139] Can't open zipfile /Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg: IOError: [Errno 13] file not accessible: '/Users/ca/.pythonbrew/venvs/Python-2.7.2/project_name/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg'

我可能错了,但似乎这是之前没有出现过的问题。自2011年12月13日发布Google App Engine以来,我想知道是否可能与这个版本有关。

我正在使用pythonbrew、virtualenv和Mac Os X 10.6.8。

谢谢你的帮助!

6个回答

14

我有另一种解决他的问题的答案,这是我亲身经历过的。如果你有一个像这样的模板目录:

templates
|-- css
|-- img
|-- js
|-- html

你的 app.yaml 文件应该像这样:

- url: /templates
  static_dir: templates

如果您使用以下名称,则无法使用jinja2渲染模板:

JINJA_ENVIRONMENT.get_template('html/index.html')

我认为这是因为static_dir选项在某种程度上阻止了jinja2访问该目录,至少我是这样认为的,也许会对某些人有所帮助!


5
是的,我遇到了这个问题。目前GAE不允许从应用程序代码中访问static_dir中的文件。 - MrD
1
这只是默认行为。但可以使用 application_readable: true 选项来覆盖它,请参阅 https://dev59.com/zXLYa4cB1Zd3GeqPTBCg#16541092 - Dan Cornilescu

6

只需从您的站点包中删除文件setuptools-0.6c11-py2.7.egg

找到站点包的位置

启动python CLI:

python

列出网站的包:
>>> import site; site.getsitepackages()

4

现在我不再使用硬编码的路径变量来引用我的变量,而是使用:

PROJECT_DIR = os.path.dirname(__file__)

它已经起作用了。如果问题再次发生(我看到一些文章将其描述为随机复发),我会让你知道。

我还在http://code.google.com/p/googleappengine/issues/detail?id=4339上应用了29号评论中的补丁。


我应该把这个 PROJECT_DIR 添加到哪里? - shadyabhi
我有一个settings.py文件,我会在需要访问那些全局变量的所有文件中导入它。 - charlax

3
可能会晚一些,但也许会帮到其他人。
因此,当您添加

时,
jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates'))
请勿将
- url: /templates static_dir: templates
添加到您的app.yaml文件中。

或者也可以添加 application_readable: true。https://dev59.com/zXLYa4cB1Zd3GeqPTBCg#16541092 - Dan Cornilescu

0
在某些情况下,这个错误是由于dev_appserver.py在文件名与app.yaml中的skip_files模式匹配时返回打开调用失败所致。即使在本地运行dev_appserver.py时,请检查app.yaml。

0

我一直被类似的问题困扰 - 从site-packages导入egg文件/包时出现IOError。我使用的是Ubuntu 13.10,GAE 1.8.8,virtualenv和python 2.7。

最后,我发现我无法导入任何使用easy_install安装的东西(默认情况下将egg文件放入site_packages中)。

一旦我卸载了所有这些egg,并使用pip install命令重新安装,一切都开始正常工作。

希望这能为其他人节省时间,因为我永远也找不回浪费的时间了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接