Title: Python Crashes when trying to access any date related fields in MailItem
Type: crash Stage:
Components: Windows Versions: Python 3.7
Status: open Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: erikjanss, paul.moore, ronaldoussoren, steve.dower, tim.golden, vijay, xtreak, zach.ware
Priority: normal Keywords:

Created on 2018-08-31 07:47 by vijay, last changed 2018-09-11 16:40 by erikjanss.

File name Uploaded Description Edit
python crash.PNG vijay, 2018-08-31 07:47
Messages (11)
msg324406 - (view) Author: Vijay (vijay) Date: 2018-08-31 07:47
MailItem.SentOn or MailItem.ReceivedTime, Python crashes with windows showing "Python has stopped working" dialog window. What can be the cause of this issue?

import win32com.client
import os
import datetime
from datetime import timedelta
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
message = messages.GetLast()


t = message.ReceivedTime   ---- crashes when the script is reached this line.

Attached the screenshot for your reference.
msg324417 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2018-08-31 12:54
There is a very similar SO question which points to an AttributeError. Is this a case where Python segfaults or there is some stacktrace? Any chance you can provide the message or a reproducible script for this? I also hope this is something related specifically to Windows and someone might add in here about this.

msg324418 - (view) Author: Vijay (vijay) Date: 2018-08-31 13:18
i have already added the script. try to run in the python3.7. python is getting crashed.
msg324421 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2018-08-31 14:20
win32com is part of pywin32, which is a 3th-party extension. Please check with that project first (if there is bug it is probably on that side).
msg324514 - (view) Author: Vijay (vijay) Date: 2018-09-03 12:59
Thanks for the inputs. i will check with pywin32 team.
is there any pywin32 link to raise the case. please share if you know.
msg324517 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2018-09-03 13:41
This might help :


Karthikeyan S
msg324713 - (view) Author: Erik Janssens (erikjanss) * Date: 2018-09-06 21:49
for what's it worth, I've observed similar crashes under these strange circumstances :

- the crashes don't appear in python 3.4, but they do in 3.5 (maybe due to switch in msvc runtime)

- the crashes do appear when run as script, the exact same commands in the repl work as expected

- the crashes behave the same when using ActiveQt/PyQt instead of pywin32, which suggests it's not a pywin32 issue
msg325004 - (view) Author: Vijay (vijay) Date: 2018-09-11 12:00
can someone please clarify, is it a pywin32 issue or python3.7 issue?.
msg325014 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2018-09-11 14:59
There's not enough information in the issue to be sure, but I'm inclined to say this is a 3th-party problem.  To be sure someone will have to reproduce the problem in a debugger, or provide a stack trace of the crash.

The initial message says there's a crash when using pywin32 to access particular COM APIs, and msg324713 says that the same thing can happen when using PyQt.

Either project is 3th-party, as is the actual COM dispatch machinery in Windows. And the past has shown that crashes that happen when 3th-party extensions are involved are almost never due to bugs in CPython.

@erikjanss: I'm assuming that you mean that using PyQt to access and outlook COM API can cause a crash, is that correct?
msg325026 - (view) Author: Erik Janssens (erikjanss) * Date: 2018-09-11 16:37
@ronaldoussoren In my case it was not Outlook, it was a third party line of business application,
but as in the case of the OP, as mentioned in the StackOverflow link, the crashing only happens using certain Python version.

I'm not suggesting the issue of the OP (nor mine) is in CPython.  But it's strange at least that it depends on the Python version, and that it does not crash when using the REPL (I did try to compensate for delays etc.).

I took the PyQt route to 'proof' the issue is not related to pywin32.

When running it in a debugger, the crash happens in an MFC dll, after the Invoke of the COM method.

So my guess is the issue is related to some incompatibility in MSVC libraries between CPython and the line of business application.
msg325027 - (view) Author: Erik Janssens (erikjanss) * Date: 2018-09-11 16:40
@vijay may I suggest you try to investigate your issue in more detail :

- does it depend on the Python version ?  If so which versions work, which dont.

- does the crash happen as well when using the REPL ?

- if you use PyQt instead of pywin32, does it still crash ?

Not that any of these suggestions will lead to a clear solution, but it might at least rule out some things.
Date User Action Args
2018-09-11 16:40:52erikjansssetmessages: + msg325027
2018-09-11 16:37:45erikjansssetmessages: + msg325026
2018-09-11 14:59:35ronaldoussorensetmessages: + msg325014
2018-09-11 12:00:25vijaysetmessages: + msg325004
2018-09-06 21:49:21erikjansssetnosy: + erikjanss
messages: + msg324713
2018-09-03 13:41:56xtreaksetmessages: + msg324517
2018-09-03 12:59:18vijaysetmessages: + msg324514
2018-08-31 14:20:56ronaldoussorensetnosy: + ronaldoussoren, paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg324421

components: + Windows
resolution: third party
2018-08-31 13:18:07vijaysetmessages: + msg324418
2018-08-31 12:54:08xtreaksetnosy: + xtreak
messages: + msg324417
2018-08-31 07:47:43vijaycreate