2013-01-02 48 views
5

我想從Google應用程序引擎應用程序訪問我的計算機中的文件。如果我將該文件放在應用程序的src文件夾中,則沒有問題,但我需要此文件超出該文件夾。IOError:[Errno 13]文件無法訪問GAE

當我嘗試訪問該文件,我得到了一個錯誤:

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) 

是否有人知道爲什麼我會得到「文件不可訪問「錯誤?

謝謝!

+0

的可能重複[ IOError:\ [Errno 13 \]文件無法通過Google AppEngine 1.6.1訪問](http://stackoverflow.com/questions/8799304/ioerror-errno-13-file-not-accessible-with-google-appengine-1 -6-1) – bain

回答

9

將文件放在與其他應用程序文件(即app.yaml所在的位置)相同的目錄中。

您希望應用程序訪問的所有文件必須位於主應用程序目錄下的相同位置。

GAE無法訪問計算機上某處的任意文件,就像在部署時無法訪問其他地方保存的文件一樣。

filename='myfile.doc' 

這是假設它在'根'(與app.yaml相同)。

+1

即使它可以訪問這些文件,也可以在Google上運行的應用程序中對其硬盤上的位置進行硬編碼雲是一個壞主意。如果Google可以直接訪問您的硬盤驅動器,他們不會告訴您這一點。 – geoffspear

+0

感謝您的回答! – user1930068

0

在你的app.yaml文件,你需要做可見的文件到您的應用程序:

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

舉例來說,在我的app.yaml文件,它看起來像這樣

- url: /data 
    script: main.app