【问题标题】:IIS flask is not able to run admin privilege commandsIIS 烧瓶无法运行管理员权限命令
【发布时间】:2020-08-27 16:11:57
【问题描述】:

我在这个设置中卡住了将近一个星期。希望有人能指导我。

设置

  1. 我已经设置了一个运行 Flask python 代码的 IIS 服务器。 (使用 wfastcgi.py )

  2. 我已将应用程序池标识配置为我自己的帐户。 (管理员权限)

  3. 我已将此 Web 部署所需的所有文件权限更改为“所有人” - 完全控制(读取、写入、执行)。 (我了解安全风险,这是我的暂存环境。)

  4. 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"
    

问题陈述

  1. 我正在尝试在我的烧瓶 IIS 服务器上运行管理员 priv 代码,该代码允许同一网络中的用户执行;比如

     subprocess.run(['ipconfig'], stdout=subprocess.PIPE)
    
     pyautogui.screenshot() #which take a screenshot of the web server and send over to the client.
    
  2. 我在本地的 jupyter notebook 上运行,上面的功能运行良好。

  3. 但它在 IIS 烧瓶服务器上运行失败。

  4. 我也尝试在烧瓶服务器上设置 pyautogui(没有 IIS 的独立),它工作正常。

  5. 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: 

【问题讨论】:

    标签: python flask iis


    【解决方案1】:

    文件“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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-07
      • 2019-10-15
      • 1970-01-01
      • 2018-11-03
      • 2013-03-07
      • 1970-01-01
      • 2019-05-17
      • 2019-04-13
      相关资源
      最近更新 更多