python - 从 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 配置中设置了以下内容:
- AppPool 身份设置为我的
<domain>\<my username>
. - 该网站设置为“连接为...”我的
<domain>\<my username>
.
真正让我困惑的是,在 IIS 上运行脚本会打印正确的进程所有者(我),与从命令行运行脚本时相同。但是,在一种情况下我可以访问 UNC 共享,在另一种情况下它会失败。
解决方案
推荐阅读
- android - Android导航组件导航到上一个片段
- java - 使用 Jackson 解析具有重复元素的 XML
- node.js - 如何将 HMSET 与节点 promisify 一起使用
- django - 如何根据 django 中以前使用的密码检查密码
- javascript - Javascript承诺问题
- python - 使用路径组将 csv 文件导入 hdf5 python
- python - Tensorflow 和 Tensorflow.JS 给出不同的预测
- ruby-on-rails - 如何为不同类型的用户设计数据库表?
- node.js - 由于 webpack 问题,npm start 无法正常工作
- kubernetes - Kubectl 命令如何从远程服务器检索清单