2013-05-28 124 views
1

使用下面的代碼在Windows 64中下載和執行文件時遇到了一個奇怪的錯誤。錯誤是我總是拒絕訪問。請注意,這段代碼在Linux中正常工作,當我使用Window Explorer手動設置文件的完整權限時,我可以執行它(我不知道爲什麼,因爲我的代碼已經設置了文件的完全權限)。下載並執行文件時出現問題:Python Windows 64bit

#open url 
u = urllib2.urlopen(download_url) 

#create and write to a local file 
with open(filename, 'wb') as f: 
    block_sz = 8192 
    while True: 
     buffer = u.read(block_sz) 
     if not buffer: 
      break 
     f.write(buffer) 

#set full permission to the file 
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) 
os.system(filename) 
+0

請注意,此問題只發生在Windows 64位。在Windows 32位中運行代碼時沒有問題。 –

回答

0

the docsos.chmod只能在Windows系統設置改變只讀權限。

+0

我的問題實際上是如何使文件可執行?只要文件是可執行的,文件是隻讀還是非文件並不重要。 –

0

看來這個問題是由我的木偶配置引起的,而不是python,因爲在父目錄中設置權限時存在問題。