From kristiine.silinja at gmail.com Wed Mar 3 09:27:15 2021 From: kristiine.silinja at gmail.com (Kristiine Silinja) Date: Wed, 3 Mar 2021 16:27:15 +0200 Subject: [python-win32] pywin32 building under mingw64/msys2 Message-ID: Good day! I have just pulled the master state of pywin32 from github. When building it under mingw64/msys2 on Windows I get a following error: Building pywin32 3.8.300.1 Windows 10 SDK version 10.0.16299.0 is preferred, but that's not installed Installed versions are ['10.0.19041.0'] Using 10.0.19041.0 running install running build running build_py running build_ext error: don't know how to compile C/C++ code on platform 'nt' with 'mingw64' compiler Python version: Python 3.8.7 [GCC 10.2.0 64 bit (AMD64)] on win32 Would appreciate any help in getting pywin32 installed to Python under msys2. Perhaps other libraries could be tweaked (e.g. distutils)? A quick search on the topic was not as helpful. With best regards, *-Kristiine Silinja* -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed Mar 3 16:55:20 2021 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 4 Mar 2021 08:55:20 +1100 Subject: [python-win32] pywin32 building under mingw64/msys2 In-Reply-To: References: Message-ID: <1cb5cc4a-3817-90c5-989d-f1a5806d10e3@gmail.com> There is some work going on in https://github.com/mhammond/pywin32/pull/1612, but that's largely stalled at the moment. Frankly, I've no interest in this myself, so if it happens it would need to be driven by contributors. Cheers, Mark On 4/03/2021 1:27 am, Kristiine Silinja wrote: > Good day! > > I have just pulled the master state of pywin32 from github. When > building it under mingw64/msys2 on Windows I get a following error: > Building pywin32 3.8.300.1 > Windows 10 SDK version 10.0.16299.0 is preferred, but that's not installed > Installed versions are ['10.0.19041.0'] > Using 10.0.19041.0 > running install > running build > running build_py > running build_ext > error: don't know how to compile C/C++ code on platform 'nt' with > 'mingw64' compiler > > Python version:?Python 3.8.7 [GCC 10.2.0 64 bit (AMD64)] on win32 > > Would appreciate any help in getting pywin32 installed to Python under > msys2. Perhaps other libraries could be tweaked (e.g. distutils)? A > quick search on the topic was not as helpful. > > With best regards, > /-Kristiine Silinja/ > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > From mforce2 at gmail.com Sat Mar 6 09:43:53 2021 From: mforce2 at gmail.com (Marius Cirsta) Date: Sat, 6 Mar 2021 16:43:53 +0200 Subject: [python-win32] win32com.client.WithEvents fails when running as a Windows service Message-ID: Hi, I'm trying to automate CANoe using win32com. I've written a script that works perfectly when I log in and run it as a normal user. I want to run it from a Jenkins service though and I have allowed the Jenkins service to interact with desktop or whatever that option is called. This runs just fine : myCanApp = win32com.client.Dispatch('CANoe.Application') print("CANoe dispatched!") And a CANoe instance is started. But then this code follows: onfiguration = myCanApp.Configuration measurement = myCanApp.Measurement # Getting the Test Configurations TestEnvs = Configuration.TestSetup.TestEnvironments csbTstMod = None for tstEnv in TestEnvs: if (tstEnv.Name != tstEnvName): continue tstEnv = win32com.client.CastTo(tstEnv, "ITestEnvironment2") for tstMod in tstEnv.TestModules: if (tstMod.Name == tstModName): csbTstMod = tstMod break win32com.client.WithEvents(csbTstMod, TestModuleEvents) Normally this also runs fine and I can intercept the events with my custom handler. When being run as a service though I get this error: Traceback (most recent call last): File "D:\Jenkins\Scripts\dispatch.py", line 203, in exec_test(PDConfigPath, "CommonTests", "PD_CSB") File "D:\Jenkins\Scripts\dispatch.py", line 146, in exec_test win32com.client.WithEvents(csbTstMod, TestModuleEvents) File "C:\Program Files\Python39\lib\site-packages\win32com\client\__init__.py", line 336, in WithEvents instance = result_class(disp) # This only calls the first base class __init__. File "C:\WINDOWS\TEMP\gen_py\3.9\7F31DEB0-5BCC-11D3-8562-00105A3E017Bx0x1x58.py", line 19507, in __init__ cookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy)) pywintypes.com_error: (-2147024891, 'Access is denied.', None, None) It would be really useful to understand what's going on, where the problem is as I cannot determine what permissions I need to enable ( some COM permissions ? ) for this to work as a service. As I've said interact with Desktop is on , othewise the first Dispatch of CANoe wouldn't work. I'm using the latest pywin32 installed with pip ( as Admin ) in Windows 10 ver 19xx. Any help to make any progress or debug this somehow would be appreciated. I can debug using pydevd but so far that wasn't very useful. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Sat Mar 6 21:07:59 2021 From: timr at probo.com (Tim Roberts) Date: Sat, 6 Mar 2021 18:07:59 -0800 Subject: [python-win32] win32com.client.WithEvents fails when running as a Windows service In-Reply-To: References: Message-ID: On Mar 6, 2021, at 6:43 AM, Marius Cirsta wrote: > > I'm trying to automate CANoe using win32com. I've written a script that works perfectly when I log in and run it as a normal user. > ... > When being run as a service though I get this error: > > Traceback (most recent call last): > File "D:\Jenkins\Scripts\dispatch.py", line 203, in > exec_test(PDConfigPath, "CommonTests", "PD_CSB") > File "D:\Jenkins\Scripts\dispatch.py", line 146, in exec_test > win32com.client.WithEvents(csbTstMod, TestModuleEvents) > File "C:\Program Files\Python39\lib\site-packages\win32com\client\__init__.py", line 336, in WithEvents > instance = result_class(disp) # This only calls the first base class __init__. > File "C:\WINDOWS\TEMP\gen_py\3.9\7F31DEB0-5BCC-11D3-8562-00105A3E017Bx0x1x58.py", line 19507, in __init__ > cookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy)) > pywintypes.com_error: (-2147024891, 'Access is denied.', None, None) Do you have your service configured to run as your user? The normal service user has different access permissions, so it can?t access your file shares. ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From manglavishesh64 at gmail.com Sun Mar 14 00:38:59 2021 From: manglavishesh64 at gmail.com (manglavishesh64 at gmail.com) Date: Sun, 14 Mar 2021 11:08:59 +0530 Subject: [python-win32] Use of streams than path in `wc.Dispatch("Word.Application").Documents.Open(docx_path) Message-ID: An HTML attachment was scrubbed... URL: From manglavishesh64 at gmail.com Sun Mar 14 00:44:02 2021 From: manglavishesh64 at gmail.com (Vishesh Mangla) Date: Sun, 14 Mar 2021 11:14:02 +0530 Subject: [python-win32] Use of streams than path in `wc.Dispatch("Word.Application").Documents.Open(docx_path) In-Reply-To: References: Message-ID: class PrepMessage: def __init__(self): self.msg = EmailMessage() self.templates = {} def _get_template(self, template_path): try: return copy.deepcopy(self.templates[template_path]) except KeyError: with open(template_path, "rb") as f: source_stream = StringIO(f.read()) self.templates[template_path] = DocxTemplate(source_stream) source_stream.close() return self.templates[template_path] def _get_html_string(self, html_path): """ Read message html file""" if html_path[-1] == "l": html_path = html_path[-1] with codecs.open(html_path, "r") as fp: stream = fp.read() os.remove(html_path) return stream def _get_mime(self, path): mime = mimetypes.guess_type(path)[0] if mime: return mime elif path.endswith(".rar"): return "application/x-rar-compressed" else: raise TypeError("Filetype not supported invalid") def __setitem__(self, name, val, *args, **kwargs): if name == "To": self.msg.__setitem__("To", self._get_formatted_to(val)) elif name == "Subject": self.msg.__setitem__("Subject", self ._get_formatted_subject(val)) elif name == "From": self.msg.__setitem__("From", self._get_formatted_from(val)) def _get_formatted_to(self, to): return ", ".join([i.strip() for i in to.split(",")]) def _get_formatted_subject(self, subject): return subject def _get_formatted_from(self, from_): return from_ def add_attachments(self, attachments): for file_ in map(lambda x: x.strip(), attachments.split(",")): if os.path.exists(file_): with open(file_, "rb") as fp: file_name = pathlib.Path(file_).name maintype, subtype = self._get_mime(file_name).split("/") self.msg.add_attachment( fp.read(), maintype=maintype, subtype=subtype, filename=file_name, ) def _get_path_of_converted_word_to_html(self, docx_string_io): TODO: word = wc.Dispatch("Word.Application") doc = word.Documents.Open(docx_path) html_path = "a.html" doc.SaveAs(html_path, 8) doc.Close() word.Quit() os.remove(docx_path) return html_path def add_alternative(self, docx_template_path, context): template = self._get_template(docx_template_path) template.render(context) target_stream = StringIO() template.save(target_stream) self.msg.add_alternative( self._get_html_string( self._get_path_of_converted_word_to_html(Path(word_doc)) ), subtype="html", ) On Sun, Mar 14, 2021 at 11:10 AM wrote: > > > To convert docx to html , one would do > > word = wc.Dispatch("Word.Application") > > doc = word.Documents.Open(docx_path) > > doc.SaveAs(html_path, 8) > > But here we require paths. I am using python-docx-template . I read a > docx file, template it, then save to a StringIO(). But now I have to first > save the doc as .docx, then open it and then create .html files, then deal > with PermissionErrors. How can I use the StringIO() in place of paths. > Something like this: > > > > word = wc.Dispatch("Word.Application") > > doc = word.Documents.Open(docx_string_io) > > doc.SaveAs(html_stream, 8) > > > > > > Sent from Mail for > Windows 10 > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From borutflis1 at gmail.com Fri Mar 19 17:28:44 2021 From: borutflis1 at gmail.com (Borut Flis) Date: Fri, 19 Mar 2021 22:28:44 +0100 Subject: [python-win32] Why is my object 32-bit?? Message-ID: Hello, I registered an object with pywin32. For demonstrative purposes I used a simple HelloWorld available here: https://github.com/BorutFlis/Scripts/blob/main/hello.py I can call with pywin32: import win32com.client o = win32com.client.Dispatch("Python.TestServer") It works fine. I than tried to run it with visual basic in Excel and it was not working. My Excel is 64-bit and so is my Python. After some advice I tried running the Visual Basic script with C:\Windows\System32\cscript.exe and C:\Windows\SysWOW64\cscript.exe . It works with the SysWOW64, which is where the 32-bit object are. So my COM object is 32-bit, why is that and how can I reconfigure. Also I don't know where to locate the .dll or .exe created. There is not entry at: HKEY_CLASSSES_ROOT\Wow6432Node\CLSID\{7CC9F362-486D-11D1-BB48-0000E838A65F}, only at: HKEY_CLASSSES_ROOT\Wow6432Node\AppID\{7CC9F362-486D-11D1-BB48-0000E838A65F}, but it has no info about the dll or exe. Best Regards, Borut -------------- next part -------------- An HTML attachment was scrubbed... URL: From shaiksaleem at armaxindia.com Tue Mar 30 10:52:31 2021 From: shaiksaleem at armaxindia.com (Shaik Saleem Basha) Date: Tue, 30 Mar 2021 20:22:31 +0530 Subject: [python-win32] error 1: incorrect function when starting service python Message-ID: An HTML attachment was scrubbed... URL: From timr at probo.com Tue Mar 30 13:04:19 2021 From: timr at probo.com (Tim Roberts) Date: Tue, 30 Mar 2021 10:04:19 -0700 Subject: [python-win32] error 1: incorrect function when starting service python In-Reply-To: References: Message-ID: <39ab7adc-a621-d426-cc31-0a30f9068edb@probo.com> Shaik Saleem Basha wrote: > Issue: > > 1.I have created a python script for windows service, service is > creating I can't able to run I'm getting the following error ( The > pythonftp service terminated with the following service-specific > error: Incorrect function.) in windows logs. > > 2.I'm able to run the service from windows services, only if I'm > creating service from the environment this is also working only on my > laptop the same I have tried on another laptop I'm getting the same error. > Are you sure the other laptop has the same version of Python, and the same version of all of the Python modules you require?? Are you sure that both systems have access to the D: drive?? If that's a file share, are you sure both laptops have permission to access it?? Remember that services, by default, run as the "local system" user, which does not have any of your network permissions. When you run on the other laptop, do you get a traceback that tells you which line failed?? You should share that. > 4.code link: https://cutt.ly/ux7XdnB > It is incredibly foolish of you to publish your actual FTP username and password in a public github repository.? You need to find another way to handle that. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3389 bytes Desc: S/MIME Cryptographic Signature URL: From shaiksaleem at armaxindia.com Tue Mar 30 13:17:25 2021 From: shaiksaleem at armaxindia.com (Shaik Saleem Basha) Date: Tue, 30 Mar 2021 22:47:25 +0530 Subject: [python-win32] error 1: incorrect function when starting service python In-Reply-To: <39ab7adc-a621-d426-cc31-0a30f9068edb@probo.com> References: <39ab7adc-a621-d426-cc31-0a30f9068edb@probo.com> Message-ID: Both the laptop has same version On Tue, 30 Mar 2021, 22:41 Tim Roberts, wrote: > Shaik Saleem Basha wrote: > > Issue: > > > > 1.I have created a python script for windows service, service is > > creating I can't able to run I'm getting the following error ( The > > pythonftp service terminated with the following service-specific > > error: Incorrect function.) in windows logs. > > > > 2.I'm able to run the service from windows services, only if I'm > > creating service from the environment this is also working only on my > > laptop the same I have tried on another laptop I'm getting the same > error. > > > Are you sure the other laptop has the same version of Python, and the > same version of all of the Python modules you require? Are you sure > > that both systems have access to the D: drive? If that's a file share, > are you sure both laptops have permission to access it? Remember that > services, by default, run as the "local system" user, which does not > have any of your network permissions. > > When you run on the other laptop, do you get a traceback that tells you > which line failed? You should share that. > > > > 4.code link: https://cutt.ly/ux7XdnB > > > It is incredibly foolish of you to publish your actual FTP username and > password in a public github repository. You need to find another way to > handle that. > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: