Win32com代码在IIS上不起作用 [英] Win32com codes not working on IIS

查看:110
本文介绍了Win32com代码在IIS上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当有使用win32com对象的代码被加密时,我都会尝试在IIS Web服务器上部署Python应用程序,它会引发错误,但是该代码在Python内置Web服务器上可以正常工作
这是代码:

I am trying to deploy a Python app on IIS webserver whenever there is a code that uses win32com objects is encoutered, it throws error, but the code is working fine on Python built-in webserver Here is the code:

xlapp = win32com.client.Dispatch(r Excel.Application)

xlapp = win32com.client.Dispatch(r"Excel.Application")

这是错误:

xlapp undefined, global win32com = <module 'win32com' from 'C:\Python27\lib\site-packages\win32com\__init__.pyc'>, win32com.client = <module 'win32com.client' from 'C:\Python27\lib\site-packages\win32com\client\__init__.pyc'>, win32com.client.Dispatch = <function Dispatch> 
C:\Python27\lib\site-packages\win32com\client\__init__.py in Dispatch(dispatch='Excel.Application', userName=None, resultCLSID=None, typeinfo=None, UnicodeToString=None, clsctx=21) 
 93   """

 94   assert UnicodeToString is None, "this is deprecated and will go away"

 =>   95   dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)

 96   return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)

 97 

dispatch = 'Excel.Application', userName = None, global dynamic = <module 'win32com.client.dynamic' from 'C:\Python27\lib\site-packages\win32com\client\dynamic.pyc'>, dynamic._GetGoodDispatchAndUserName = <function _GetGoodDispatchAndUserName>, clsctx = 21 
C:\Python27\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatchAndUserName(IDispatch='Excel.Application', userName='Excel.Application', clsctx=21) 
113         else:

114                 userName = str(userName)

=>  115         return (_GetGoodDispatch(IDispatch, clsctx), userName)

116 

117 def _GetDescInvokeType(entry, default_invoke_type):

global _GetGoodDispatch = <function _GetGoodDispatch>, IDispatch = 'Excel.Application', clsctx = 21, userName = 'Excel.Application' 
C:\Python27\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch='Excel.Application', clsctx=21) 
 90                         IDispatch = pythoncom.connect(IDispatch)

 91                 except pythoncom.ole_error:

=>   92                         IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)

 93         else:

 94                 # may already be a wrapped class.

IDispatch = 'Excel.Application', global pythoncom = <module 'pythoncom' from 'C:\windows\system32\pythoncom27.dll'>, pythoncom.CoCreateInstance = <built-in function CoCreateInstance>, builtin None = None, clsctx = 21, pythoncom.IID_IDispatch = IID('{00020400-0000-0000-C000-000000000046}') 

   <class 'pywintypes.com_error'>:(-2147024891, 'Access is denied.', None, None) 
  argerror = None 
  args = (-2147024891, 'Access is denied.', None, None) 
  excepinfo = None 
  hresult = -2147024891 
  message = '' 
  strerror = 'Access is denied.' 


推荐答案

提示在错误消息中:


< class'pywintypes.com_error'> ::(-2147024891,'访问被拒绝。',无,无)

argerror = None

args =(-2147024891,'访问被拒绝。',无,无)

excepinfo =无

hresu lt = -2147024891

message =''

strerror ='访问被拒绝。'

<class 'pywintypes.com_error'>:(-2147024891, 'Access is denied.', None, None)
argerror = None
args = (-2147024891, 'Access is denied.', None, None)
excepinfo = None
hresult = -2147024891
message = ''
strerror = 'Access is denied.'

您的python应用运行时所使用的身份似乎没有启动Excel实例的权限。

It looks like the identity your python app runs under doesn't have permission to launch an Excel instance.

更新:

Excel将作为进程外COM服务器启动。要允许您的网站权限启动Excel并实例化作为工作簿的对象,您需要使用名为 dcomcnfg.exe 的工具为Excel配置启动和激活权限。

Excel will be launched as an out of process COM server. To allow your website permission to launch Excel and instantiate objects which as workbooks you need to configure the Launch and Activation permissions for Excel using a tool called dcomcnfg.exe.

您可以从开始->运行或从命令行启动 dcomcnfg.exe 。您还必须是本地计算机管理员。

You can launch dcomcnfg.exe from Start -> Run or from the command line. You need to be a local machine administrator as well.

启动后,展开 Component Services 节点,它的子节点就像下面的屏幕截图所示:

Once launched expand the Component Services node and it's children just like in the screenshot below:

向下滚动 DCOM Config 节点的子项,直到找到名为 Microsoft Excel Application 的条目:

Scroll down through the children of the DCOM Config node until you find an entry called Microsoft Excel Application:

右键单击此条目并选择 Properties ,将打开一个选项卡式对话框。选择安全性标签,然后选择启动和激活权限自定义单选按钮,然后单击 Edit 按钮,如下所示:

Right click on this entry and select Properties, a tabbed dialogue box will open. Select the Security tab then select the Launch and Activation Permissions Customize radio button, then click the Edit button, just like this:

单击编辑按钮时,将打开另一个对话框,在此窗口中,您可以添加您的网站运行的身份:

When you click the Edit button another dialogue box will open, in this window you can add the identity that your website runs under:

通常该网站将在称为 应用程序池的环境下运行身份 。通常,它的名称与站点的应用程序池相同(除非您更改了名称)。

Usually the site will run under what's known as the Application Pool Identity. It will normally be the same name as the site's application pool (unless you changed that).

您需要同时授予池标识的启动和激活权限。通过单击 Add 按钮执行此操作,该按钮显示:

You need to grant both Launch and Activate permissions to the pool identity. Do this by clicking the Add button, which displays:

在文本框中输入以 IIS AppPool\为前缀的池标识。 code>(空格和反斜杠很重要:

Into the text box enter the pool identity prefixed with IIS AppPool\ (the space and backslash are important:


    IIS AppPool\[Your Application Pool Identity]

例如:


    IIS AppPool\DefaultAppPool

单击确定,您将看到应用程序池标识已添加到用户列表中,然后确保 Local Launch Local激活选中允许复选框,就像这样:

Click OK and you'll see your application pool identity added to the users list. Then make sure that the Local Launch and Local Activation Allow tick boxes are checked, just like this:

完成后,单击确定,然后再次单击确定

Once done, click OK, then click OK again.

希望现在您应该可以让Python应用程序启动Excel。

Hopefully now you should be able to have your Python app launch Excel.

我应该警告您,Excel(和其他Office套件应用程序)并非设计好的(或许可)在Web应用程序中使用。最终可能会出现数百个孤立的Excel(或Word)流程,这将成为管理/资源争夺的噩梦。

I should warn you that Excel (and other Office suite applications) are not designed (or licensed) to be used in web applications. It's possible to end up with hundreds of orphaned Excel (or Word) processes which will become a total management/resource hogging nightmare.

这篇关于Win32com代码在IIS上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆