[英]IIS flask is not able to run admin privilege commands
我現在被困在這個設置中將近一個星期了。 希望有人能指導我完成它。
設置
我已經設置了一個運行 Flask python 代碼的 IIS 服務器。 (使用 wfastcgi.py )
我已將應用程序池標識配置為我自己的帳戶。 (管理員權限)
我已將此 Web 部署所需的所有文件權限更改為“所有人” - 完全控制(讀取、寫入、執行)。 (我了解安全風險,這是我的登台環境。)
Web 服務器運行良好,我已經使用底部代碼進行了檢查,以了解我的 python 權限是管理員。
def am_i_admin(): try: is_admin = os.getuid() == 0 except AttributeError: is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 if is_admin == True: return "ADMIN" else: return "USER"
問題陳述
我試圖在我的 Flask IIS 服務器上運行管理員權限代碼,允許同一網絡中的用戶執行; 如
subprocess.run(['ipconfig'], stdout=subprocess.PIPE) pyautogui.screenshot() #which take a screenshot of the web server and send over to the client.
我在本地 jupyter notebook 上運行,上述功能運行良好。
但是在 IIS Flask 服務器上運行失敗。
我還嘗試在 Flask 服務器上設置 pyautogui(沒有 IIS 的獨立),它有效。
IIS服務器有什么問題?? 或者還有更多我需要配置的東西。 是否有可以禁用的安全功能?
子進程錯誤信息:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "c:\users\aspnet\anaconda3\lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "c:\users\aspnet\anaconda3\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "c:\users\aspnet\anaconda3\lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\my_app.py", line 58, in <module>
out = os.popen("ipconfig").read()
File "c:\users\aspnet\anaconda3\lib\os.py", line 990, in popen
bufsize=buffering)
File "c:\users\aspnet\anaconda3\lib\subprocess.py", line 753, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "c:\users\aspnet\anaconda3\lib\subprocess.py", line 1090, in _get_handles
errwrite = _winapi.GetStdHandle(_winapi.STD_ERROR_HANDLE)
OSError: [WinError 6] The handle is invalid
StdOut:
StdErr:
pyautogui 錯誤:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "c:\users\aspnet\anaconda3\lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "c:\users\aspnet\anaconda3\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "c:\users\aspnet\anaconda3\lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\my_app.py", line 45, in <module>
pyautogui.screenshot()
File "c:\users\aspnet\anaconda3\lib\site-packages\pyscreeze\__init__.py", line 135, in wrapper
return wrappedFunction(*args, **kwargs)
File "c:\users\aspnet\anaconda3\lib\site-packages\pyscreeze\__init__.py", line 427, in _screenshot_win32
im = ImageGrab.grab()
File "c:\users\aspnet\anaconda3\lib\site-packages\PIL\ImageGrab.py", line 44, in grab
include_layered_windows, all_screens
OSError: screen grab failed
StdOut:
StdErr:
文件“c:\\users\\aspnet\\anaconda3\\lib\\site-packages\\PIL\\ImageGrab.py”,第 44 行,在抓取 include_layered_windows, all_screens OSError: 屏幕抓取失敗
要解決此問題,請將 stderr 和 stdin 設置為 subprocess.PIPE:
['where', 'wkhtmltopdf'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].strip()
參考: https : //github.com/foliojs/pdfkit/issues/714
文件“c:\\users\\aspnet\\anaconda3\\lib\\site-packages\\PIL\\ImageGrab.py”,第 44 行,在抓取 include_layered_windows, all_screens OSError: 屏幕抓取失敗
使用以下代碼:
from PIL import ImageGrab
或者
from PIL import Image
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.