【问题标题】:IOError: [Errno 13] file not accessible GAEIOError:[Errno 13] 文件不可访问 GAE
【发布时间】:2013-01-02 12:03:53
【问题描述】:

我想从谷歌应用引擎应用程序访问我计算机中的文件。如果我把文件放在应用程序的 src 文件夹中没有问题,但我需要这个文件不在那个文件夹中。

当我尝试访问此文件时,出现下一个错误:

Traceback (most recent call last):
File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 712, in __call__
handler.post(*groups)
File "C:\Users\path\Documents\path\oauth2client\appengine.py", line 469, in check_oauth
return method(request_handler, *args, **kwargs)
File "C:\Users\path\Documents\path\myapp.py", line 88, in post
filename=open('C:/Users/path_to_file/Documento 1.docx','r')
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 635, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: 'C:/Users/path_to_file/Documento 1.docx'

我已经读到,如果文件在 app.yaml 中定义为静态文件,则无法从 GAE 访问。这是我的 app.yaml。不知道有没有问题:

application: myapp
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
script: myapp.py

这是尝试访问文件的应用程序部分:

filename='C:/Users/path_to_file/Documento 1.docx'
media_body = MediaFileUpload(filename,resumable=True)

有人知道我为什么会收到“文件不可访问”错误吗?

谢谢!

【问题讨论】:

标签: python google-app-engine


【解决方案1】:

将该文件与您的其他应用程序文件放在同一目录中(即 app.yaml 所在的位置)。

您希望您的应用程序访问的所有文件都必须位于您的主应用程序目录下的同一个位置。

GAE 无法访问您计算机上某处的任意文件,就像它在部署时无法访问保存在其他“某处”的文件一样。

filename='myfile.doc'

假设它位于“根”中(与 app.yaml 相同)。

【讨论】:

  • 即使它可以访问这些文件,将它们在硬盘上的位置硬编码到一个打算在谷歌云上运行的应用程序中也是一个坏主意。如果 Google 可以直接访问您的硬盘,他们不会告诉您。
【解决方案2】:

在您的 app.yaml 文件中,您需要使该文件对您的应用可见:

 handlers:
 - url: /<location to your data files>
   script: <your app name>.app

例如在我的 app.yaml 文件中,它看起来像这样

- url: /data
  script: main.app

【讨论】:

    猜你喜欢
    • 2012-07-14
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 2011-06-11
    • 2013-05-02
    • 2016-02-28
    • 1970-01-01
    相关资源
    最近更新 更多