首页 > 解决方案 > 从 IIS python CGI 脚本访问 UNC 共享

问题描述

我需要从在 IIS (7.5) 上运行的 Python (3.6) CGI 脚本访问 UNC 共享上的文件。我的最小测试示例是:

import os
import psutil
print('Content-Type: text/html\n')
print(psutil.Process(os.getpid()).username())
print(os.path.exists('\\\\<server name>\\<folder>'))

当我从命令行运行此脚本时,它会打印所需的输出:

> python cgi-bin\test.py
Content-Type: text/html

<domain>\<my username>
True

但是,当我通过访问 IIS 在 IIS 上运行它http://localhost/my-site/cgi-bin/test.py时,我得到:

<domain>\<my username>
False

请注意,我在 IIS 配置中设置了以下内容:

真正让我困惑的是,在 IIS 上运行脚本会打印正确的进程所有者(我),与从命令行运行脚本时相同。但是,在一种情况下我可以访问 UNC 共享,在另一种情况下它会失败。

标签: pythoniiscginas

解决方案


推荐阅读