From rob at mymcgillivray.com Sun Nov 4 03:20:07 2012 From: rob at mymcgillivray.com (Rob McGillivray) Date: Sat, 3 Nov 2012 22:20:07 -0400 Subject: [python-win32] Win32 service not calling SvcShutdown() Message-ID: Hi All, For the life of me I cannot figure out why SvcShutdown() is not being called when the OS shuts down. All the other SCM notifications (pause/continue/stop) work just fine. I have searched high & low for solutions, but nothing. What appears to be a slam-dunk for others completely evades me. I must be missing something, so I bought a copy of Programming on Win32, but the Services section hasn't shed any more light on the issue, so I humbly ask for enlightenment. :-) What the heck am I missing?? Your help would be much appreciated! Thanks in advance, Rob ------------------------- import win32serviceutil import servicemanager import win32service import win32event import win32api import datetime LOGINFO = 0 LOGWARNING = 1 LOGERROR = 2 class MyService(win32serviceutil.ServiceFramework): _svc_name_ = 'MyService' _svc_display_name_ = 'MyService service' def __init__(self, *args): win32serviceutil.ServiceFramework.__init__(self, *args) # Create events for service stop, pause & continue # CreateEvent(securityAttrs, bManualReset, bInitialState, name) self.evStop = win32event.CreateEvent(None, 0, 0, None) self.evPause = win32event.CreateEvent(None, 0, 0, None) self.evContinue = win32event.CreateEvent(None, 0, 0, None) # Create event list for WaitForMultipleObjects() self.evhandles = self.evStop, self.evPause, self.evContinue # sigStatus must be this range for a valid SCM event self.validSignals = range(win32event.WAIT_OBJECT_0, win32event.MAXIMUM_WAIT_OBJECTS) # Signal ID returned from WFMO() else None self.sigStatus = None # Service run state. False means pausing/paused or stopping self.runState = True def logEvent(self, msg, logtype=LOGINFO, logcategory=None): import servicemanager if logtype == LOGINFO: servicemanager.LogInfoMsg(str(msg)) elif logtype == LOGWARNING: servicemanager.LogWarningMsg(str(msg)) elif logtype == LOGERROR: servicemanager.LogErrorMsg(str(msg)) def sleep(self, sec): '''A delay method sympathetic to SCM notifications.''' while sec > 0: # SCM event has taken place? if self.notificationFromSCM(): break win32api.Sleep(1000) sec -= 1 def notificationFromSCM(self): '''Returns True if SCM notification(s) have taken place. sigStatus has the value. Note: that calls to WaitForMultipleObjects() only returns the event status ONCE, after which it's reset (ie. calling it may return WAIT_OBJECT_0 and an immediate subsequent call will yield WAIT_TIMEOUT or similar.''' if self.sigStatus is not None: # Still have a live SCM event to process, so exit return True # WaitForMultipleObjects(handles, bWaitAll, dwMilliseconds) self.sigStatus = win32event.WaitForMultipleObjects(self.evhandles, 0, 0) if self.sigStatus in self.validSignals: return True else: # Timeout signal or similar, so MUST reset sigStatus self.sigStatus = None return False def SvcDoRun(self): self.ReportServiceStatus(win32service.SERVICE_START_PENDING) self.logEvent('Starting {0} Service...'.format(self._svc_display_name_)) self.ReportServiceStatus(win32service.SERVICE_RUNNING) self.logEvent('{0} Service started.'.format(self._svc_display_name_)) while True: if self.runState: try: # Insert service work activity here... self.logEvent('Working: {0}'.format(datetime.datetime.now())) self.sleep(10) except Exception as x: self.logEvent('Exception : {0}'.format(x), LOGERROR) else: self.sleep(30) # SCM notification? if self.notificationFromSCM(): if self.sigStatus == self.evhandles.index(self.evStop): # STOP event self.logEvent('Stopping {0} Service...'.format(self._svc_display_name_)) break elif self.sigStatus == self.evhandles.index(self.evPause): # PAUSE event self.logEvent('Pausing {0} Service...'.format(self._svc_display_name_)) self.runState = False # Other cleanup code here... self.logEvent('{0} Service paused.'.format(self._svc_display_name_)) self.ReportServiceStatus(win32service.SERVICE_PAUSED) elif self.sigStatus == self.evhandles.index(self.evContinue): # CONTINUE event self.logEvent('Resuming {0} service...'.format(self._svc_display_name_)) self.runState = True # Reset pause & continue to non-signaled state win32event.ResetEvent(self.evPause) win32event.ResetEvent(self.evContinue) # Other cleanup code here... self.logEvent('{0} Service started.'.format(self._svc_display_name_)) self.ReportServiceStatus(win32service.SERVICE_RUNNING) # Clear signal flag self.sigStatus = None # If we get here, then service has been stopped/shutdown self.logEvent('{0} Service stopped.'.format(self._svc_display_name_)) self.ReportServiceStatus(win32service.SERVICE_STOPPED) def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # Signal STOP event win32event.SetEvent(self.evStop) def SvcPause(self): self.ReportServiceStatus(win32service.SERVICE_PAUSE_PENDING) # Signal PAUSE event win32event.SetEvent(self.evPause) def SvcContinue(self): self.ReportServiceStatus(win32service.SERVICE_CONTINUE_PENDING) # Signal CONTINUE event win32event.SetEvent(self.evContinue) def SvcShutdown(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) self.logEvent('**SvcShutdown event**') # Shutdown code here... win32event.SetEvent(self.evStop) From skippy.hammond at gmail.com Mon Nov 5 01:35:48 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 05 Nov 2012 11:35:48 +1100 Subject: [python-win32] Win32 service not calling SvcShutdown() In-Reply-To: References: Message-ID: <509709E4.6060103@gmail.com> On 4/11/2012 1:20 PM, Rob McGillivray wrote: > Hi All, > > For the life of me I cannot figure out why SvcShutdown() is not being called when the OS shuts down. All the other SCM notifications (pause/continue/stop) work just fine. I have searched high & low for solutions, but nothing. What appears to be a slam-dunk for others completely evades me. I must be missing something, so I bought a copy of Programming on Win32, but the Services section hasn't shed any more light on the issue, so I humbly ask for enlightenment. :-) What the heck am I missing?? > > Your help would be much appreciated! > > Thanks in advance, > > Rob I'm guessing here, but... > def SvcShutdown(self): > self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) > self.logEvent('**SvcShutdown event**') It is possible that by the time you get here the eventlog service has also stopped. Have you tried to verify the call any other way (eg, writing a line to a file? > # Shutdown code here... > win32event.SetEvent(self.evStop) Your shutdown code probably shouldn't be there - it should be in the main SvcDoRun function - how much of a problem this is probably depends on how much work it does. Also, your use of events seems a little fragile - would it be possible for you to use manual reset events, so that your notificationFromSCM() function doesn't reset the event? Even better would be to remove it completely - your sleep() function could just a WaitForMultipleObjects with a timeout of sec*1000. So if you still have problems, it might be best to demonstrate it with one of the sample pywin32 services so (a) we can reproduce it and (b) it eliminates some of the complexity in your real service. HTH, Mark From mhammond at skippinet.com.au Mon Nov 5 02:33:02 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 05 Nov 2012 12:33:02 +1100 Subject: [python-win32] Win32 service not calling SvcShutdown() In-Reply-To: <80EA254F-D780-4127-A3C3-C653747A764C@mymcgillivray.com> References: <509709E4.6060103@gmail.com> <80EA254F-D780-4127-A3C3-C653747A764C@mymcgillivray.com> Message-ID: <5097174E.5070709@skippinet.com.au> [re-adding python-win32] On 5/11/2012 12:08 PM, Rob McGillivray wrote: > Hi Mark, > > Much appreciate the feedback! Many thanks. > > I'll try writing something to a file and check this out ? I never > thought that the event log service could/would stop(?). Doesn't the > event log service run continuously and support all Windows services > logging requests? Or do you get some handle to an 'event logger' > object upon launch of python service.exe? I do have a book on NT > Services that I'll peruse a little more based on your feedback. > > My understanding from your chapter on services is that the service > only ceases to 'exist' once SvcDoRun ends, so I thought I was safe > signaling on SvcShutdown event. If the shutdown is happening so > quickly, then I am concerned, because the 'cleanup/shutdown' code may > take 10-15sec to complete. I thought I could advise the SCM of this > delay, since the default timeout shows a wait hint of 5sec? Clearly > my understanding is a little foggy here, so any enlightenment would > be appreciated. That's generally correct - although you should probably still do the shutdown work in the DoRun methods - the shutdown notification is likely to come in on a different thread. > Also appreciate the comment on the fragility of my use of events. > It's my first time using them, and much of what I coded I > 'translated' from the NT Services book (written in C++). Funny thing > is that I started with sleep function as you describe with a timeout > of 1000msec, and then 'improved' it to it's current state. I'll > recode it in the light of your feedback. Thanks again. > > PS: I also bought your Programming Python to teach this old(er) dog > new tricks, and it's been a great read, showing a sense of humor and > comic relief quite devoid most dev books on my shelf. :-) Thanks :) Mark From mhammond at skippinet.com.au Mon Nov 5 02:33:43 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 05 Nov 2012 12:33:43 +1100 Subject: [python-win32] Win32 service not calling SvcShutdown() In-Reply-To: <232948D4-A49B-4873-87C4-A47C86272EAA@mymcgillivray.com> References: <509709E4.6060103@gmail.com> <80EA254F-D780-4127-A3C3-C653747A764C@mymcgillivray.com> <232948D4-A49B-4873-87C4-A47C86272EAA@mymcgillivray.com> Message-ID: <50971777.20003@skippinet.com.au> [re-adding python-win32] On 5/11/2012 12:21 PM, Rob McGillivray wrote: > Mark, > > You are correct. I wrote to a file and the SvcShutdown() event is > being fired. My question is ? surely the event log service would only > stop once all other dependent services have also stopped? Is your service dependent on the eventlog service? IIUC, the eventlog service just immediately shuts down when it set the shutdown event. > How do > other services manage to write shutdown type notifications to the > event log upon shutdown? Is there some Windows event log resource > that I can grab and hold until I've had an opportunity to log my > 'exit' events to prevent premature shutdown of the event log > service? I guess you could explicitly make it depend on the eventlog service? Mark > > Your thoughts would be appreciated. > > Kind regards, > > Rob > > On Nov 4, 2012, at 8:08 PM, Rob McGillivray > wrote: > >> Hi Mark, >> >> Much appreciate the feedback! Many thanks. >> >> I'll try writing something to a file and check this out ? I never >> thought that the event log service could/would stop(?). Doesn't the >> event log service run continuously and support all Windows services >> logging requests? Or do you get some handle to an 'event logger' >> object upon launch of python service.exe? I do have a book on NT >> Services that I'll peruse a little more based on your feedback. >> >> My understanding from your chapter on services is that the service >> only ceases to 'exist' once SvcDoRun ends, so I thought I was safe >> signaling on SvcShutdown event. If the shutdown is happening so >> quickly, then I am concerned, because the 'cleanup/shutdown' code >> may take 10-15sec to complete. I thought I could advise the SCM of >> this delay, since the default timeout shows a wait hint of 5sec? >> Clearly my understanding is a little foggy here, so any >> enlightenment would be appreciated. >> >> Also appreciate the comment on the fragility of my use of events. >> It's my first time using them, and much of what I coded I >> 'translated' from the NT Services book (written in C++). Funny >> thing is that I started with sleep function as you describe with a >> timeout of 1000msec, and then 'improved' it to it's current state. >> I'll recode it in the light of your feedback. Thanks again. >> >> PS: I also bought your Programming Python to teach this old(er) dog >> new tricks, and it's been a great read, showing a sense of humor >> and comic relief quite devoid most dev books on my shelf. :-) >> >> Kind regards, >> >> Rob >> >> >> On Nov 4, 2012, at 7:35 PM, Mark Hammond >> wrote: >> >>> On 4/11/2012 1:20 PM, Rob McGillivray wrote: >>>> Hi All, >>>> >>>> For the life of me I cannot figure out why SvcShutdown() is not >>>> being called when the OS shuts down. All the other SCM >>>> notifications (pause/continue/stop) work just fine. I have >>>> searched high & low for solutions, but nothing. What appears to >>>> be a slam-dunk for others completely evades me. I must be >>>> missing something, so I bought a copy of Programming on Win32, >>>> but the Services section hasn't shed any more light on the >>>> issue, so I humbly ask for enlightenment. :-) What the heck am >>>> I missing?? >>>> >>>> Your help would be much appreciated! >>>> >>>> Thanks in advance, >>>> >>>> Rob >>> >>> I'm guessing here, but... >>> >>>> def SvcShutdown(self): >>>> self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) >>>> self.logEvent('**SvcShutdown event**') >>> >>> It is possible that by the time you get here the eventlog service >>> has also stopped. Have you tried to verify the call any other >>> way (eg, writing a line to a file? >>> >>>> # Shutdown code here... win32event.SetEvent(self.evStop) >>> >>> Your shutdown code probably shouldn't be there - it should be in >>> the main SvcDoRun function - how much of a problem this is >>> probably depends on how much work it does. >>> >>> Also, your use of events seems a little fragile - would it be >>> possible for you to use manual reset events, so that your >>> notificationFromSCM() function doesn't reset the event? >>> >>> Even better would be to remove it completely - your sleep() >>> function could just a WaitForMultipleObjects with a timeout of >>> sec*1000. >>> >>> So if you still have problems, it might be best to demonstrate it >>> with one of the sample pywin32 services so (a) we can reproduce >>> it and (b) it eliminates some of the complexity in your real >>> service. >>> >>> HTH, >>> >>> Mark >>> >> > > From rob at mymcgillivray.com Mon Nov 5 17:17:18 2012 From: rob at mymcgillivray.com (Rob McGillivray) Date: Mon, 5 Nov 2012 11:17:18 -0500 Subject: [python-win32] Event log doesn't log events on SvcShutdown() event in service Message-ID: Hello All, This email is a follow-on from my last post to which Mark kindly gave me some pointers. I have a service and all is working as advertised, besides the fact that the eventlog service does not log any events during the implementation of the shutdown event in SvcDoRun(). Tested both Win7 and Win Server 2003. Mark's comment was the the eventlog service had most likely shut down by time I made my request, so try making the service dependent upon the eventlog service, which I did, but to no avail. I then logged all actions to file as he suggested, which shows pretty clearly that all the events from the SCM are firing correctly and are being handled by my service: 2012-11-05 10:32:19.590000: Doing my work... 2012-11-05 10:32:32.944000: SvcPause event on controlhandler thread 2012-11-05 10:32:32.944000: PAUSE event in SvcDoRun() 2012-11-05 10:32:39.402000: SvcContinue event on controlhandler thread 2012-11-05 10:32:39.402000: CONTINUE event in SvcDoRun() 2012-11-05 10:32:39.402000: Doing my work... 2012-11-05 10:32:49.099000: SvcShutdown event on controlhandler thread 2012-11-05 10:32:49.099000: SHUTDOWN event in SvcDoRun() **However, the event log does not show the last call to the eventlog service "Shutting down the service?" per the code below. The last log entry for my service in the event log is "Doing my work?"** I can't make sense of this. Surely if my service is dependent upon eventlog service, then this service must remain alive at least until my service terminates? I checked several other services for their dependencies, and they happily log shutdown notifications, BUT show NO dependency upon the eventlog as a service, so how exactly do they ensure that their events are dutifully logged during the shutdown process? Moreover, if I notify the SCM upon shutdown within SvcDoRun() that my service is stopping, but needs a little more time, eg. ~10sec before entering the stopped state by calling ReportServiceStatus(win32service.SERVICE_STOP_PENDING, waitHint=10000), the waitHint is not respected, and the service still shuts down immediately. Your thoughts would be much appreciated. (If there is a better way of listing code, please advise). Thanks in advance, Rob ------ #!/usr/bin/env python3 # Import helper modules from os.path import splitext, abspath from sys import modules # Import pywin32 modules import win32serviceutil import servicemanager import win32service import win32event import win32api import datetime class MyService(win32serviceutil.ServiceFramework): _svc_name_ = 'MyService' _svc_display_name_ = 'MyService Name' _svc_deps_ = 'eventlog', def __init__(self, *args): win32serviceutil.ServiceFramework.__init__(self, *args) # All manual reset events self.evStop = win32event.CreateEvent(None, True, 0, None) self.evPause = win32event.CreateEvent(None, True, 0, None) self.evContinue = win32event.CreateEvent(None, True, 0, None) self.evShutdown = win32event.CreateEvent(None, True, 0, None) self.evhandles = self.evStop, self.evPause, self.evContinue, self.evShutdown self.validSignals = range(win32event.WAIT_OBJECT_0, win32event.MAXIMUM_WAIT_OBJECTS) # Signal ID returned from WFMO() else None self.sigStatus = 0 def logEvent(self, msg): servicemanager.LogInfoMsg(str(msg)) def sleep(self, sec): while sec > 0: # SCM event has taken place? if win32event.WaitForMultipleObjects(self.evhandles, 0, 1000) in self.validSignals: break sec -= 1 def logToFile(self, msg): with open('c:\myservice.txt', 'a') as f: f.write('{0}: {1}\r\n'.format(datetime.datetime.today(), msg)) def SvcDoRun(self): self.logEvent('Service started.') running = True while True: if running: self.logEvent('Doing my work...') self.logToFile('Doing my work...') self.sleep(30) # SCM notification? self.sigStatus = win32event.WaitForMultipleObjects(self.evhandles, 0, 1000) if self.sigStatus == self.evhandles.index(self.evStop): # STOP event self.logToFile('STOP event in SvcDoRun()') self.logEvent('Stopping service...') break elif self.sigStatus == self.evhandles.index(self.evPause): # PAUSE event self.logToFile('PAUSE event in SvcDoRun()') self.logEvent('Pausing service...') self.ReportServiceStatus(win32service.SERVICE_PAUSE_PENDING) running = False win32event.ResetEvent(self.evPause) # Other cleanup code here... self.logEvent('Service paused.') self.ReportServiceStatus(win32service.SERVICE_PAUSED) elif self.sigStatus == self.evhandles.index(self.evContinue): # CONTINUE event self.logToFile('CONTINUE event in SvcDoRun()') self.logEvent('Resuming service...') self.ReportServiceStatus(win32service.SERVICE_CONTINUE_PENDING) running = True # Reset pause & continue to non-signaled state win32event.ResetEvent(self.evContinue) # Other cleanup code here... self.logEvent('Service started.') self.ReportServiceStatus(win32service.SERVICE_RUNNING) elif self.sigStatus == self.evhandles.index(self.evShutdown): # SHUTDOWN event self.logToFile('SHUTDOWN event in SvcDoRun()') self.logEvent('Shutting down Service...') self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, waitHint=10000) win32api.Sleep(8000) break def SvcStop(self): # Signal STOP event self.logToFile('SvcStop event on controlhandler thread') win32event.SetEvent(self.evStop) def SvcPause(self): # Signal PAUSE event self.logToFile('SvcPause event on controlhandler thread') win32event.SetEvent(self.evPause) def SvcContinue(self): # Signal CONTINUE event self.logToFile('SvcContinue event on controlhandler thread') win32event.SetEvent(self.evContinue) def SvcShutdown(self): # Signal SHUTDOWN event self.logToFile('SvcShutdown event on controlhandler thread') win32event.SetEvent(self.evShutdown) if __name__ == '__main__': win32serviceutil.HandleCommandLine(MyService) -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhammond at skippinet.com.au Tue Nov 6 23:44:42 2012 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 07 Nov 2012 09:44:42 +1100 Subject: [python-win32] Fwd: Re: Win32 service not calling SvcShutdown() In-Reply-To: <1E97ADFD-DD3B-47B6-8725-7D1F34686290@mymcgillivray.com> References: <1E97ADFD-DD3B-47B6-8725-7D1F34686290@mymcgillivray.com> Message-ID: <509992DA.8030807@skippinet.com.au> An update on the service shutdown problem... -------------- next part -------------- An embedded message was scrubbed... From: Rob McGillivray Subject: Re: [python-win32] Win32 service not calling SvcShutdown() Date: Tue, 6 Nov 2012 11:59:35 -0500 Size: 18643 URL: From mmorrigan at gmail.com Wed Nov 7 18:50:00 2012 From: mmorrigan at gmail.com (Martha Morrigan) Date: Wed, 7 Nov 2012 15:50:00 -0200 Subject: [python-win32] Printing a text over an image Message-ID: Hi guys, Using python, wxpython and sqlite in a windows system, Im trying to print some certificates/diplomas/cards with a image at background with the name of person/text over it. I know the basic steps to print the text using win32print from Pywin32 but...: 1) I dont know how to add an image and set it to background. while ..... ..... # Query sqlite rows and collumn name and set the self.text for each certificate ..... # Now send to printer DC = win32ui.CreateDC() DC.CreatePrinterDC(win32print.GetDefaultPrinter()) DC.SetMapMode(win32con.MM_TWIPS) DC.StartDoc("Certificates Job") DC.StartPage() ux = 1000 uy = -1000 lx = 5500 ly = -55000 DC.DrawText(self.text, (ux, uy, lx, ly),win32con.DT_LEFT) DC.EndPage() DC.EndDoc() This printer-code is inside a while loop calling each people name from a sqlite database per check condition. 2) All the names of database was printed at same page... how i command the printer to spit out 1 page per name from the database? 3) Any more simple approach or module to deals with printers (paper and/or pdf) will be welcome. Thanks in advance, Martha -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Nov 9 18:45:26 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 9 Nov 2012 09:45:26 -0800 Subject: [python-win32] Printing a text over an image In-Reply-To: References: Message-ID: <509D4136.6040705@probo.com> Martha Morrigan wrote: > > Using python, wxpython and sqlite in a windows system, Im trying to > print some certificates/diplomas/cards with a image at background with > the name of person/text over it. > > I know the basic steps to print the text using win32print from Pywin32 > but...: > > 1) I dont know how to add an image and set it to background. There's really no concept of foreground and background in a printed page. The stuff you print last goes over the top of the stuff you print first. So, after you do StartDoc, you'd need to draw your image with DC.BitBlt. That's skipping over the details of how you get a bitmap object from an image file... > This printer-code is inside a while loop calling each people name from > a sqlite database per check condition. > 2) All the names of database was printed at same page... how i command > the printer to spit out 1 page per name from the database? If you really had that code inside a loop, you should see one print job per person, with one page per job. I assume you'd rather have one print job (one "document") with multiple pages. You ought to be able to figure that out. Everything up through StartDoc is creating the "document", and should be done once. Everything between StartPage and EndPage is creating a page. You'd want that inside your loop. > 3) Any more simple approach or module to deals with printers (paper > and/or pdf) will be welcome. Printing is surprisingly hard, especially when working directly with the Win32 API as you are. I use the ReportLab package for creating PDFs, but it seems like your task is simple enough that you ought to be able to make this work. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From arttan2001 at gmail.com Sat Nov 10 13:32:12 2012 From: arttan2001 at gmail.com (pythonStudent) Date: Sat, 10 Nov 2012 04:32:12 -0800 (PST) Subject: [python-win32] ImportError: No module named xxxxxx In-Reply-To: References: Message-ID: <1352550732125-4995442.post@n6.nabble.com> Hello, When I issue the following statement: >>> import win32com.client I got the following result: Traceback (most recent call last): File "", line 1, in import win32com.client ImportError: No module named win32com.client These happened too with the following statements: >>> from xlrd import open_workbook Traceback (most recent call last): File "", line 1, in from xlrd import open_workbook ImportError: No module named xlrd >>> import pythoncom Traceback (most recent call last): File "", line 1, in import pythoncom ImportError: No module named pythoncom I there anything I need to do first or install first before I execute these statements? Please help. Thank you. -- View this message in context: http://python.6.n6.nabble.com/Opening-Modifying-and-Saving-an-Excel-File-from-Python-tp1951870p4995442.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From werner.bruhin at free.fr Sat Nov 10 14:13:19 2012 From: werner.bruhin at free.fr (Werner F. Bruhin) Date: Sat, 10 Nov 2012 14:13:19 +0100 Subject: [python-win32] ImportError: No module named xxxxxx In-Reply-To: <1352550732125-4995442.post@n6.nabble.com> References: <1352550732125-4995442.post@n6.nabble.com> Message-ID: On 10/11/2012 13:32, pythonStudent wrote: > Hello, > > When I issue the following statement: > >>>> import win32com.client > > I got the following result: > > Traceback (most recent call last): > File "", line 1, in > import win32com.client > ImportError: No module named win32com.client install win32 com http://starship.python.net/~skippy/win32/Downloads.html > > These happened too with the following statements: > >>>> from xlrd import open_workbook > > Traceback (most recent call last): > File "", line 1, in > from xlrd import open_workbook > ImportError: No module named xlrd install xlrd http://pypi.python.org/pypi/xlrd >>>> import pythoncom > > Traceback (most recent call last): > File "", line 1, in > import pythoncom > ImportError: No module named pythoncom http://starship.python.net/~skippy/win32/Downloads.html > > > I there anything I need to do first or install first before I execute these > statements? Yeap, see above Werner From breamoreboy at yahoo.co.uk Sat Nov 10 14:19:31 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 10 Nov 2012 13:19:31 +0000 Subject: [python-win32] ImportError: No module named xxxxxx In-Reply-To: <1352550732125-4995442.post@n6.nabble.com> References: <1352550732125-4995442.post@n6.nabble.com> Message-ID: On 10/11/2012 12:32, pythonStudent wrote: > Hello, > > When I issue the following statement: > >>>> import win32com.client > > I got the following result: > > Traceback (most recent call last): > File "", line 1, in > import win32com.client > ImportError: No module named win32com.client > > These happened too with the following statements: > >>>> from xlrd import open_workbook > > Traceback (most recent call last): > File "", line 1, in > from xlrd import open_workbook > ImportError: No module named xlrd >>>> import pythoncom > > Traceback (most recent call last): > File "", line 1, in > import pythoncom > ImportError: No module named pythoncom > > > I there anything I need to do first or install first before I execute these > statements? > Please help. > > Thank you. > You'll need to install all of them before the import will work as none of them are provided with the standard Python distribution from python.org. The easist way to do this is to get easy_install, and either use this directly to get the modules you want or use it to install pip, and then use pip. -- Cheers. Mark Lawrence. From stefan at sofa-rockers.org Mon Nov 12 14:12:20 2012 From: stefan at sofa-rockers.org (Stefan Scherfke) Date: Mon, 12 Nov 2012 14:12:20 +0100 Subject: [python-win32] Catching SIGBREAK with Python 3.3 Message-ID: <50A0F5B4.5010001@sofa-rockers.org> Hi all, recently I?ve been playing around with sending and catching signals on Windows. I finally found out how to send and catch a BREAK event. With Python 2.7(.2), I only need os.kill(pid, signal.CTRL_C_EVENT) and signal.signal(signal.SIGBREAK, handler). Alternatively, I can use GenerateConsoleCtrlEvent and SetConsoleCtrlHandler via ctypes. However, the former does not work with Python 3.3 (64bit) and the latter always raises a KeyError in Python?s threading module. My question is: Should signal.signal(signal.SIGBREAK, handler) work under Python 3.3? If so, what am I doing wrong? Why raises the ctypes-variant an error while the signal-variant doesn?t? Below is a minimal example illustrating my problem: # sigterm_min.py import os import signal import subprocess import sys import time WIN = (sys.platform == 'win32') kwargs = {} if WIN: kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP def parent(): proc = subprocess.Popen(['python', 'sigterm_min.py', 'child'], **kwargs) time.sleep(1) if WIN: # This works on Python 2.7 and 3.3: os.kill(proc.pid, signal.CTRL_BREAK_EVENT) # Alternative (ugly) way: # import ctypes # ctypes.windll.kernel32.GenerateConsoleCtrlEvent( # signal.CTRL_BREAK_EVENT, proc.pid) else: proc.terminate() print('parent waiting for child') proc.wait() print('parent terminating') def child(): def handler(signum, frame=None): print('child terminating') sys.exit(0) if WIN: # This only works on Python 2.7, but not on 3.3: signal.signal(signal.SIGBREAK, handler) # (Ugly) alternative that works on both Python 2.7 and 3.3, # but raises a KeyError in threading.py: # import ctypes # handler = ctypes.WINFUNCTYPE(ctypes.c_int, # ctypes.c_uint)(handler) # ctypes.windll.kernel32.SetConsoleCtrlHandler(handler, True) else: signal.signal(signal.SIGTERM, handler) time.sleep(10) if __name__ == '__main__': if len(sys.argv) == 1: parent() elif sys.argv[1] == 'child': child() # EOF Cheers, Stefan From steffen.froemer at gns-systems.de Tue Nov 13 15:15:26 2012 From: steffen.froemer at gns-systems.de (=?ISO-8859-15?Q?Steffen_Fr=F6mer?=) Date: Tue, 13 Nov 2012 15:15:26 +0100 Subject: [python-win32] check if comserver is registered, no -> install it? Message-ID: <50A255FE.8070108@gns-systems.de> Hi, i have to check, if a comserver-dll is registered in my system. comserver is registered via command "regsvr32.exe /i myComServer.dll" My System is Windows 7 64bit or Windows Server 2008 R2 64 bit. Is there a way to check this with python and if the check fails, can i register this? How can i do this? I am grateful for any tip. Regards, Steffen From timr at probo.com Tue Nov 13 19:05:28 2012 From: timr at probo.com (Tim Roberts) Date: Tue, 13 Nov 2012 10:05:28 -0800 Subject: [python-win32] check if comserver is registered, no -> install it? In-Reply-To: <50A255FE.8070108@gns-systems.de> References: <50A255FE.8070108@gns-systems.de> Message-ID: <50A28BE8.1010003@probo.com> Steffen Fr?mer wrote: > i have to check, if a comserver-dll is registered in my system. > > comserver is registered via command "regsvr32.exe /i myComServer.dll" > My System is Windows 7 64bit or Windows Server 2008 R2 64 bit. > > Is there a way to check this with python and if the check fails, can i > register this? > How can i do this? There is no danger in redoing a registration that has already been done. All it does is add some registry keys. Might as well just do it every time. Add "/s" if you don't want to see the dialog box. Alternatively, assuming you are running a 64-bit Python, you can just call the registration entry point directly: import ctypes dll = ctypes.OleDLL('myComServer.dll') dll.DllRegisterServer() That's exactly what Regsvr32 does. It is not a highly sophisticated application. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mail at timgolden.me.uk Tue Nov 13 21:44:28 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 13 Nov 2012 20:44:28 +0000 Subject: [python-win32] Catching SIGBREAK with Python 3.3 In-Reply-To: <50A0F5B4.5010001@sofa-rockers.org> References: <50A0F5B4.5010001@sofa-rockers.org> Message-ID: <50A2B12C.2070706@timgolden.me.uk> On 12/11/2012 13:12, Stefan Scherfke wrote: > Hi all, > > recently I?ve been playing around with sending and catching signals on > Windows. I finally found out how to send and catch a BREAK event. > > With Python 2.7(.2), I only need os.kill(pid, signal.CTRL_C_EVENT) and > signal.signal(signal.SIGBREAK, handler). Alternatively, I can use > GenerateConsoleCtrlEvent and SetConsoleCtrlHandler via ctypes. > > However, the former does not work with Python 3.3 (64bit) and the latter > always raises a KeyError in Python?s threading module. > > My question is: Should signal.signal(signal.SIGBREAK, handler) work > under Python 3.3? If so, what am I doing wrong? Why raises the > ctypes-variant an error while the signal-variant doesn?t? Possibly unhelpfully, I've just run your code on Python 2.7, 3.3 and 3.4, all of which gave the same output: parent waiting for child child terminating parent terminating This is on WinXP SP3. That said, there has been quite a bit of activity around the handling of Ctrl-C / Ctrl-Break and KeyboardInterrupt around 3.2 so it wouldn't surprise me if something has changed there. TJG From stefan at sofa-rockers.org Tue Nov 13 21:54:22 2012 From: stefan at sofa-rockers.org (Stefan Scherfke) Date: Tue, 13 Nov 2012 21:54:22 +0100 Subject: [python-win32] Catching SIGBREAK with Python 3.3 In-Reply-To: <50A2B12C.2070706@timgolden.me.uk> References: <50A0F5B4.5010001@sofa-rockers.org> <50A2B12C.2070706@timgolden.me.uk> Message-ID: <5408CCAD-D5B8-41C7-99BE-A9122E2C797F@sofa-rockers.org> Hi Tim, Am 13.11.2012 um 21:44 schrieb Tim Golden : > On 12/11/2012 13:12, Stefan Scherfke wrote: >> Hi all, >> >> recently I?ve been playing around with sending and catching signals on >> Windows. I finally found out how to send and catch a BREAK event. >> >> With Python 2.7(.2), I only need os.kill(pid, signal.CTRL_C_EVENT) and >> signal.signal(signal.SIGBREAK, handler). Alternatively, I can use >> GenerateConsoleCtrlEvent and SetConsoleCtrlHandler via ctypes. >> >> However, the former does not work with Python 3.3 (64bit) and the latter >> always raises a KeyError in Python?s threading module. >> >> My question is: Should signal.signal(signal.SIGBREAK, handler) work >> under Python 3.3? If so, what am I doing wrong? Why raises the >> ctypes-variant an error while the signal-variant doesn?t? > > Possibly unhelpfully, I've just run your code on Python 2.7, 3.3 and 3.4, all of which gave the same output: > > parent waiting for child > child terminating > parent terminating > > This is on WinXP SP3. did you get this output immediately (within 1 or 2 seconds) or after a while? The child terminates on its own after 10 seconds, but it shouldn?t get there. Cheers, Stefan > > That said, there has been quite a bit of activity around the handling of Ctrl-C / Ctrl-Break and KeyboardInterrupt around 3.2 so it wouldn't surprise me if something has changed there. > > TJG -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2772 bytes Desc: not available URL: From mail at timgolden.me.uk Tue Nov 13 22:57:55 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 13 Nov 2012 21:57:55 +0000 Subject: [python-win32] Catching SIGBREAK with Python 3.3 In-Reply-To: <5408CCAD-D5B8-41C7-99BE-A9122E2C797F@sofa-rockers.org> References: <50A0F5B4.5010001@sofa-rockers.org> <50A2B12C.2070706@timgolden.me.uk> <5408CCAD-D5B8-41C7-99BE-A9122E2C797F@sofa-rockers.org> Message-ID: <50A2C263.9050101@timgolden.me.uk> On 13/11/2012 20:54, Stefan Scherfke wrote: > Hi Tim, > > Am 13.11.2012 um 21:44 schrieb Tim Golden : >> Possibly unhelpfully, I've just run your code on Python 2.7, 3.3 and 3.4, all of which gave the same output: >> >> parent waiting for child >> child terminating >> parent terminating >> >> This is on WinXP SP3. > > did you get this output immediately (within 1 or 2 seconds) or after a while? > The child terminates on its own after 10 seconds, but it shouldn?t get there. I wasn't timing it but certainly less than 10 seconds; 2 or 3 seconds perhaps. TJG From mail at timgolden.me.uk Wed Nov 14 13:58:02 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 14 Nov 2012 12:58:02 +0000 Subject: [python-win32] Catching SIGBREAK with Python 3.3 In-Reply-To: <5408CCAD-D5B8-41C7-99BE-A9122E2C797F@sofa-rockers.org> References: <50A0F5B4.5010001@sofa-rockers.org> <50A2B12C.2070706@timgolden.me.uk> <5408CCAD-D5B8-41C7-99BE-A9122E2C797F@sofa-rockers.org> Message-ID: <50A3955A.1030305@timgolden.me.uk> On 13/11/2012 20:54, Stefan Scherfke wrote: > Hi Tim, > > Am 13.11.2012 um 21:44 schrieb Tim Golden : > >> On 12/11/2012 13:12, Stefan Scherfke wrote: >>> Hi all, >>> >>> recently I?ve been playing around with sending and catching signals on >>> Windows. I finally found out how to send and catch a BREAK event. >>> >>> With Python 2.7(.2), I only need os.kill(pid, signal.CTRL_C_EVENT) and >>> signal.signal(signal.SIGBREAK, handler). Alternatively, I can use >>> GenerateConsoleCtrlEvent and SetConsoleCtrlHandler via ctypes. >>> >>> However, the former does not work with Python 3.3 (64bit) and the latter >>> always raises a KeyError in Python?s threading module. >>> >>> My question is: Should signal.signal(signal.SIGBREAK, handler) work >>> under Python 3.3? If so, what am I doing wrong? Why raises the >>> ctypes-variant an error while the signal-variant doesn?t? And just a little more data. I've run a slightly modified version of your code on a Win7 box with the same results. Slightly modified because I realised that your subprocess.call was calling "python" which would be running 2.7 on my box. I modified it to call sys.executable and added a print(sys.version) at the top of the parent & child. I also added a line to indicate that the child had finished sleeping rather than having been signalled. It worked as expected for 2.7, 3.2, 3.3 & 3.4 3.3 & 3.4 were slightly slower to respond. That might be due to a change to the interpreter loop to avoid a (slightly obscure) race condition when Ctrl-C was pressed. TJG From stefan at sofa-rockers.org Wed Nov 14 17:47:51 2012 From: stefan at sofa-rockers.org (Stefan Scherfke) Date: Wed, 14 Nov 2012 17:47:51 +0100 Subject: [python-win32] Catching SIGBREAK with Python 3.3 In-Reply-To: <50A3955A.1030305@timgolden.me.uk> References: <50A0F5B4.5010001@sofa-rockers.org> <50A2B12C.2070706@timgolden.me.uk> <5408CCAD-D5B8-41C7-99BE-A9122E2C797F@sofa-rockers.org> <50A3955A.1030305@timgolden.me.uk> Message-ID: <860C81AB-A25A-4147-A0AB-0389BB080978@sofa-rockers.org> Am 14.11.2012 um 13:58 schrieb Tim Golden : > On 13/11/2012 20:54, Stefan Scherfke wrote: >> Hi Tim, >> >> Am 13.11.2012 um 21:44 schrieb Tim Golden : >> >>> On 12/11/2012 13:12, Stefan Scherfke wrote: >>>> Hi all, >>>> >>>> recently I?ve been playing around with sending and catching signals on >>>> Windows. I finally found out how to send and catch a BREAK event. >>>> >>>> With Python 2.7(.2), I only need os.kill(pid, signal.CTRL_C_EVENT) and >>>> signal.signal(signal.SIGBREAK, handler). Alternatively, I can use >>>> GenerateConsoleCtrlEvent and SetConsoleCtrlHandler via ctypes. >>>> >>>> However, the former does not work with Python 3.3 (64bit) and the latter >>>> always raises a KeyError in Python?s threading module. >>>> >>>> My question is: Should signal.signal(signal.SIGBREAK, handler) work >>>> under Python 3.3? If so, what am I doing wrong? Why raises the >>>> ctypes-variant an error while the signal-variant doesn?t? > > And just a little more data. I've run a slightly modified version of > your code on a Win7 box with the same results. Slightly modified because > I realised that your subprocess.call was calling "python" which would be > running 2.7 on my box. I modified it to call sys.executable and added a > print(sys.version) at the top of the parent & child. I also added a line > to indicate that the child had finished sleeping rather than having been > signalled. > > It worked as expected for 2.7, 3.2, 3.3 & 3.4 > > 3.3 & 3.4 were slightly slower to respond. That might be due to a change > to the interpreter loop to avoid a (slightly obscure) race condition > when Ctrl-C was pressed. It seems like the sleep()-call cannot be interrupted. I added the changes you described to my code. Under XP, Py33 32bit, the child process takes 10s to terminate but doesn?t prints the last message. If I replace the sleep(10) call with a "for i in range(10): sleep(1)", the child terminates after the first call. Python 2.7 (32bit, winxp) however can interrupt the sleep(10)-call immediately. Cheers, Stefan > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2772 bytes Desc: not available URL: From mail at timgolden.me.uk Wed Nov 14 21:23:25 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 14 Nov 2012 20:23:25 +0000 Subject: [python-win32] Catching SIGBREAK with Python 3.3 In-Reply-To: <860C81AB-A25A-4147-A0AB-0389BB080978@sofa-rockers.org> References: <50A0F5B4.5010001@sofa-rockers.org> <50A2B12C.2070706@timgolden.me.uk> <5408CCAD-D5B8-41C7-99BE-A9122E2C797F@sofa-rockers.org> <50A3955A.1030305@timgolden.me.uk> <860C81AB-A25A-4147-A0AB-0389BB080978@sofa-rockers.org> Message-ID: <50A3FDBD.8080908@timgolden.me.uk> On 14/11/2012 16:47, Stefan Scherfke wrote: > It seems like the sleep()-call cannot be interrupted. I added the changes you > described to my code. Under XP, Py33 32bit, the child process takes 10s to > terminate but doesn?t prints the last message. If I replace the sleep(10) call > with a "for i in range(10): sleep(1)", the child terminates after the first > call. > > Python 2.7 (32bit, winxp) however can interrupt the sleep(10)-call immediately. Without the time to dig too deeply at the moment, I assume it's an odd interaction between the CRT implementation of the signal handler and the code, newly-added for Python 3.3, specifically to allow Ctrl-C to interrupt time.sleep. I'll try to dig a bit more when I have some time. TJG From Nitin_Kumar3 at McAfee.com Fri Nov 16 12:53:48 2012 From: Nitin_Kumar3 at McAfee.com (Nitin_Kumar3 at McAfee.com) Date: Fri, 16 Nov 2012 11:53:48 +0000 Subject: [python-win32] Context menu for library Message-ID: <99BF678AA9903444947981DA6EE1D9660129D5@DNVEXAPAC1N2.corp.nai.org> Hi, I want to fetch all the context menus for Windows 7 Libraries (Documents,Music,Pictures...). As for these libraries we can't find any registry as we have shellex entry for files and folders. Can anyone please let me know how can we can get context menu items using python? Thanks Nitin K [mfe_primary_logo_rgb] -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 1922 bytes Desc: image001.jpg URL: From rupole at hotmail.com Sat Nov 17 01:52:51 2012 From: rupole at hotmail.com (Roger Upole) Date: Fri, 16 Nov 2012 19:52:51 -0500 Subject: [python-win32] Context menu for library References: <99BF678AA9903444947981DA6EE1D9660129D5@DNVEXAPAC1N2.corp.nai.org> Message-ID: You should be able to get the context menu by creating a shell item for the library file (using eg shell.SHCreateShellItem), and then call BindToHandler using BHID_SFUIObject and IID_IContextMenu. That should result in an IContextMenu object, from which you can fill in a menu handle using QueryContextMenu. You'd then need to call IContextMenu.GetCommandString for each item id in the menu (and probably submenus too). Roger wrote in message news:99BF678AA9903444947981DA6EE1D9660129D5 at DNVEXAPAC1N2.corp.nai.org... Hi, I want to fetch all the context menus for Windows 7 Libraries (Documents,Music,Pictures...). As for these libraries we can't find any registry as we have shellex entry for files and folders. Can anyone please let me know how can we can get context menu items using python? Thanks Nitin K [mfe_primary_logo_rgb] -------------------------------------------------------------------------------- > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From claudiu.curca at skype.net Wed Nov 28 21:20:34 2012 From: claudiu.curca at skype.net (Claudiu Curca) Date: Wed, 28 Nov 2012 20:20:34 +0000 Subject: [python-win32] Read timeout with liburl2 on HTTPS connection with non-standard port Message-ID: <9E3D98FB7606F44CB831320842C9ED8709308355@DB3EX14MBXC307.europe.corp.microsoft.com> Hello all, I am trying to find out the reason for some weird behavior on Windows. We have the following code: import urllib2 req = urllib2.Request("https://benotificationsmock.cloudapp.net:8443") resp = urllib2.urlopen(req, timeout = 5) print resp.code This simple script should print "200". However, all I ever get when running this on any Windows machine (for reference, mine is Windows 7, Python 2.7.3 and OpenSSL 1.0.0c / 0.9.8x) is the following exception: Traceback (most recent call last): File "foo.py", line 5, in resp = urllib2.urlopen(req, timeout = 5) File "C:\Python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "C:\Python27\lib\urllib2.py", line 400, in open response = self._open(req, data) File "C:\Python27\lib\urllib2.py", line 418, in _open '_open', req) File "C:\Python27\lib\urllib2.py", line 378, in _call_chain result = func(*args) File "C:\Python27\lib\urllib2.py", line 1215, in https_open return self.do_open(httplib.HTTPSConnection, req) File "C:\Python27\lib\urllib2.py", line 1177, in do_open raise URLError(err) urllib2.URLError: Firewalls are not at fault here, as netstat reports that the connection is being established. The only problem is that reading from the socket seems to fail. The exact same code runs fine on Linux. The only way to make it work on Windows is to remove the non-standard port. Did anyone else encounter this weird behavior? Can anyone give any suggestions? Any feedback would be greatly appreciated. Best regards, Claudiu -- Claudiu CURC? Software Development Engineer in Test II / Backend Core Prague / Microsoft Skype Division Telephone: +40 741 289 849 Skype: claudiu_curca -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Thu Nov 29 18:56:44 2012 From: timr at probo.com (Tim Roberts) Date: Thu, 29 Nov 2012 09:56:44 -0800 Subject: [python-win32] Read timeout with liburl2 on HTTPS connection with non-standard port In-Reply-To: <9E3D98FB7606F44CB831320842C9ED8709308355@DB3EX14MBXC307.europe.corp.microsoft.com> References: <9E3D98FB7606F44CB831320842C9ED8709308355@DB3EX14MBXC307.europe.corp.microsoft.com> Message-ID: <50B7A1DC.7080201@probo.com> Claudiu Curca wrote: > > Hello all, > > > > I am trying to find out the reason for some weird behavior on Windows. > > > > We have the following code: > > > > import urllib2 > > > > req = urllib2.Request("https://benotificationsmock.cloudapp.net:8443") > > resp = urllib2.urlopen(req, timeout = 5) > > print resp.code > > > > This simple script should print ?200?. However, all I ever get when > running this on any Windows machine (for reference, mine is Windows 7, > Python 2.7.3 and OpenSSL 1.0.0c / 0.9.8x) is the following exception: > I see the same thing here. However, I also get a timeout when I try that request from Firefox. Forgive the silly question, but you're sure the port is supposed to be 8443? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Nov 29 20:58:44 2012 From: timr at probo.com (Tim Roberts) Date: Thu, 29 Nov 2012 11:58:44 -0800 Subject: [python-win32] Read timeout with liburl2 on HTTPS connection with non-standard port In-Reply-To: <9E3D98FB7606F44CB831320842C9ED870930D8DA@DB3EX14MBXC307.europe.corp.microsoft.com> References: <9E3D98FB7606F44CB831320842C9ED8709308355@DB3EX14MBXC307.europe.corp.microsoft.com> <50B7A1DC.7080201@probo.com> <9E3D98FB7606F44CB831320842C9ED870930D8DA@DB3EX14MBXC307.europe.corp.microsoft.com> Message-ID: <50B7BE74.2030501@probo.com> Claudiu Curca wrote: > Hello Tim, > > You must've hit the servers while they were rolling some update. It is working for me in browser and curl. Can you please try again? Yes, it now works for me, both in Firefox and in your Python script C:\tmp>type x.py import urllib2 req = urllib2.Request("https://benotificationsmock.cloudapp.net:8443") resp = urllib2.urlopen(req, timeout = 5) print resp.code C:\tmp>x.py 200 C:\tmp> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From claudiu.curca at skype.net Thu Nov 29 19:17:13 2012 From: claudiu.curca at skype.net (Claudiu Curca) Date: Thu, 29 Nov 2012 18:17:13 +0000 Subject: [python-win32] Read timeout with liburl2 on HTTPS connection with non-standard port In-Reply-To: <50B7A1DC.7080201@probo.com> References: <9E3D98FB7606F44CB831320842C9ED8709308355@DB3EX14MBXC307.europe.corp.microsoft.com> <50B7A1DC.7080201@probo.com> Message-ID: <9E3D98FB7606F44CB831320842C9ED870930D8DA@DB3EX14MBXC307.europe.corp.microsoft.com> Hello Tim, You must've hit the servers while they were rolling some update. It is working for me in browser and curl. Can you please try again? Thanks! -----Original Message----- From: python-win32 [mailto:python-win32-bounces+claudiuc=microsoft.com at python.org] On Behalf Of Tim Roberts Sent: joi, 29 noiembrie 2012 18:57 To: Python-Win32 List Subject: Re: [python-win32] Read timeout with liburl2 on HTTPS connection with non-standard port Claudiu Curca wrote: > > Hello all, > > > > I am trying to find out the reason for some weird behavior on Windows. > > > > We have the following code: > > > > import urllib2 > > > > req = urllib2.Request("https://benotificationsmock.cloudapp.net:8443") > > resp = urllib2.urlopen(req, timeout = 5) > > print resp.code > > > > This simple script should print "200". However, all I ever get when > running this on any Windows machine (for reference, mine is Windows 7, > Python 2.7.3 and OpenSSL 1.0.0c / 0.9.8x) is the following exception: > I see the same thing here. However, I also get a timeout when I try that request from Firefox. Forgive the silly question, but you're sure the port is supposed to be 8443? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From michael at siteshadow.com Fri Nov 30 21:12:02 2012 From: michael at siteshadow.com (Michael Wilson) Date: Fri, 30 Nov 2012 14:12:02 -0600 Subject: [python-win32] python-win32 Digest, Vol 116, Issue 13 In-Reply-To: References: Message-ID: Hi everyone, I am new to Python. Been poking at it for about a month now. I am trying to set up a list for information on people. For example: person 0's name = "Sam". li[0][0] person 0's hoppy = "skateboarding" li[0][1] person 0's favorite color = ["green", "red"] li[0][2] # it appears i can put another list inside of the list, ie li[0][2]=[x,y,z] very cool! we couldn't do that in my grandpa languages. Would that be done with a li[0].append(['green','red']) after I'm done defining li[0][1]?? Then, I could just do a li[0][2].extend(['purple','mauve']) if more colors were ever needed? person 0's favorite numbers = [1, 3, 5-10, 78] li[0][3] # ranges of numbers? person 1's name = "Mary" li[1][0] etc.. My thought if there's not already an elegant solution in Python is to create a flag 'r' before ranges. So, the example here would become [1,3,'r',5,10,18,78]. Then I just do a > < query to find a match. How does that sound? newNum = 8 numHit = False for i in range(len(li[x][3])): if li[x][3][i] == 'r': if li[x][3][i+1] < newNum > li[x][3][i+2]: # I didn't do <= and >= because the = parts will be evaluated in the next 2 iterations of the loop numHit == True else: if newNum == li[x][3][i]: numHit == True if numHit: print "You picked one of " + li[x][0] + "'s lucky numbers!" How does that look? Is that ~ the best way to address my problem? Thanks! Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Nov 30 22:20:28 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 30 Nov 2012 13:20:28 -0800 Subject: [python-win32] python-win32 Digest, Vol 116, Issue 13 In-Reply-To: References: Message-ID: <50B9231C.8090402@probo.com> In the future, I'd like to suggest that you choose a genuine subject line when you post. It makes people more inclined to read your messages. Michael Wilson wrote: > > My thought if there's not already an elegant solution in Python is to > create a flag 'r' before ranges. So, the example here would become > [1,3,'r',5,10,18,78]. Then I just do a > < query to find a match. How > does that sound? I can think of several approaches. For a range, you could add a two-tuple instead of an integer: nums = [1, 3, (5,10), 18, 78] You can tell the difference at runtime: for item in nums: if type(item) == tuple: numHit = (newNum >= item[0]) and (newNum <= item[1]) else: numHit = newNum == item To eliminate the special case, you could embed ALL of the numbers as ranges of size one: nums = [ (1,1), (3,3), (5,10), (18,18), (78,78) ] Or, unless you plan to allow numbers in the millions, just add the whole range to the list individually: nums = [1, 3] nums.extend( range(5,10+1) ) nums.append( 18 ) nums.append( 78 ) > for i in range(len(li[x][3])): Almost always, when you write a for loop with range(len(xxx)), you can do the same thing without them: for i in li[x][3]: If you really do need the index, you can do: for index, i in enumerate(li[x][3]): -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Paul_Koning at Dell.com Fri Nov 30 22:23:56 2012 From: Paul_Koning at Dell.com (Paul_Koning at Dell.com) Date: Fri, 30 Nov 2012 21:23:56 +0000 Subject: [python-win32] python-win32 Digest, Vol 116, Issue 13 In-Reply-To: <50B9231C.8090402@probo.com> References: <50B9231C.8090402@probo.com> Message-ID: On Nov 30, 2012, at 4:20 PM, Tim Roberts wrote: > In the future, I'd like to suggest that you choose a genuine subject > line when you post. It makes people more inclined to read your messages. > > > Michael Wilson wrote: >> >> My thought if there's not already an elegant solution in Python is to >> create a flag 'r' before ranges. So, the example here would become >> [1,3,'r',5,10,18,78]. Then I just do a > < query to find a match. How >> does that sound? > > I can think of several approaches. For a range, you could add a > two-tuple instead of an integer: > nums = [1, 3, (5,10), 18, 78] > You can tell the difference at runtime: > for item in nums: > if type(item) == tuple: Nit: the Pythonic recommended way of doing this is "if isinstance (item, tuple):" The difference is that this will also work if item is an instance of a subclass of "tuple" while the original code does not handle that case. For this code, that might not be an interesting scenario, but in other places it might be. It's worth getting into the habit of using "isinstance". paul From timr at probo.com Fri Nov 30 22:27:24 2012 From: timr at probo.com (Tim Roberts) Date: Fri, 30 Nov 2012 13:27:24 -0800 Subject: [python-win32] python-win32 Digest, Vol 116, Issue 13 In-Reply-To: References: <50B9231C.8090402@probo.com> Message-ID: <50B924BC.1010807@probo.com> Paul_Koning at Dell.com wrote: > > Nit: the Pythonic recommended way of doing this is "if isinstance (item, tuple):" > > The difference is that this will also work if item is an instance of a subclass of "tuple" while the original code does not handle that case. For this code, that might not be an interesting scenario, but in other places it might be. It's worth getting into the habit of using "isinstance". Well said. I have several bad Python habits that I should work on eliminating... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc.