【问题标题】:Issue with downloading and executing a file: Python Windows 64bit下载和执行文件的问题:Python Windows 64bit
【发布时间】:2013-05-23 11:07:29
【问题描述】:

使用以下代码在 Windows 64 中下载和执行文件时遇到一个奇怪的错误。错误是我总是拒绝访问。请注意,此代码在 Linux 中运行良好,当我使用 Window Explorer 手动设置文件的完全权限时,我可以执行它(我不知道为什么,因为我的代码已经设置了文件的完全权限)。

#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 位中运行代码没有问题。

标签: python windows file permissions 32bit-64bit


【解决方案1】:

根据the docs,os.chmod只能在Windows系统上设置更改只读权限。

【讨论】:

  • 我的问题实际上是如何使文件可执行?文件是否为只读并不重要,只要它是可执行文件即可。
【解决方案2】:

问题似乎是由我的 puppet 配置引起的,而不是 python,因为在父目录中设置权限存在问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 2012-08-23
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多