#570 astimezone could not process time on Pythonwin for 3.2

win32 (141)

Runing the testPersist.py
Timezone processing failed on python32

returning Stat 1
pythoncom error: Unexpected exception in gateway method '<unknown>'

ValueError: astimezone() cannot be applied to a naive datetime
pythoncom error: Unexpected gateway error

ValueError: astimezone() cannot be applied to a naive datetime
Set Size0
Traceback (most recent call last):
File "C:\Python32\Lib\site-packages\win32com\test\testPersist.py", line 204, in <module>
File "C:\Python32\Lib\site-packages\win32com\test\testPersist.py", line 134, in test
stcom = pythoncom.StgCreateDocfileOnILockBytes(lbcom, storagecon.STGM_DIRECT| storagecon.STGM_CREATE | storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE, 0)
pywintypes.com_error: (-2147467259, 'Unspecified error', None, None)


  • Jason R. Coombs

    Jason R. Coombs - 2011-11-15
    • assigned_to: jaraco --> nobody
  • Jason R. Coombs

    Jason R. Coombs - 2011-11-15

    I'm not familiar with building pywin32 from scratch. Are there instructions somewhere on how to build pywin32 on Python 3? I don't have VS2008 handy, so I tried using VS2010 and patched msvc9compilermodule with jaraco.develop.msvc (https://bitbucket.org/jaraco/jaraco.develop/src/5d0574e79d6f/jaraco/develop/msvc.py), but I'm still unable to build.

    Furthermore, I don't think this is an issue with win32timezone. "astimezone()" is a method on a datetime.datetime object (part of the stdlib). I don't think win32timezone comes into play.

    Furthermore, the text 'timezone' doesn't appear in testPersist.py. I don't understand what testPersist.py is trying to do. I think the errors about naive datetimes are coming from some other code which is opaque to testPersist.

    I don't feel qualified to address this issue, so I'm going to re-assign this to no one.

  • Anthony

    Anthony - 2011-11-16

    The Error is generated by pythoncom.StgCreateDocfileOnILockBytes call from testPersist.py" . Which is located in PyTime.cpp. line 806.
    I am building pywin by using VisualStudio 2008sp1. Simply Run setup.py build in the source code directory.
    When I am tracking down, it seems that from python3, astimezone should function should have timezone information to convert the correct time.
    I did not yet indentify where PyWinObject_AsSYSTEMTIME is called.

  • Anthony

    Anthony - 2011-11-19

    This issues is cause in PyObject *PyIPropertyStorage::SetTimes(PyObject *self, PyObject *args).
    File PyIpropertyStorage.cpp line 622, which is called by Com Storage creation.

    PyWinObject_AsFILETIME not set the timezone information will cause failed of SetTimes.

  • Anthony

    Anthony - 2011-11-22

    This issue could be fixed by change win32\src\PywinTypes.h from line 470 to 484 as follwings:

    #if (PY_VERSION_HEX < 0x03000000)

    // Python 2.3 doesn't have C Api for datetime, so can't have our new funky
    // support.
    #if (PY_VERSION_HEX >= 0x02040000)

    // XXX - fixme - ack - we don't yet like *both* defines existing - and for now
    // its only enabled in py3k
    #if (PY_VERSION_HEX > 0x03000000)

    This issue is caused by old, crap, custom time object, using standard one will be OK

  • Anthony

    Anthony - 2011-11-22
    • status: open --> open-accepted
  • Jason R. Coombs

    Jason R. Coombs - 2011-11-22

    Anthony, thanks for tracking this down.

    Mark, can you take a look at the proposed workaround. I don't understand the implications of the change, and I'm guessing you can do a better review of the patch than me.

  • Jason R. Coombs

    Jason R. Coombs - 2011-11-22
    • labels: 2248529 --> win32
    • assigned_to: nobody --> mhammond
  • Mark Hammond

    Mark Hammond - 2012-01-02
    • status: open-accepted --> closed-fixed
  • Mark Hammond

    Mark Hammond - 2012-01-02

    This is just a problem in testPersist.py, which I've fixed in 4181:cc10aa149c2c. I'll have a look at issue 2831327 next.

  • foxyshadis

    foxyshadis - 2012-07-09

    I'm using build 217 on py3.2 and still getting the same error in a different function:

    win32file.SetFileTime(winfile, wintime, None, None)
    ValueError: astimezone() cannot be applied to a naive datetime

    SetFileTime also makes use of PyWinObject_AsFILETIME()

    If I get a chance at work before anyone looks at it I'll try to set up a python build environment to see if the same fix will work for this function.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks