使用下面的代碼在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)
請注意,此問題只發生在Windows 64位。在Windows 32位中運行代碼時沒有問題。 –