comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

runtime error 91: object variable or with block variable not set

Open den-run-ai opened this issue 6 years ago • 0 comments

Simple call to a method from library with one argument (string). This works as expected in pywin32.

image

Debug output:

> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(602)call_with_inout()
    601         def call_with_inout(self_, *args, **kw):
--> 602             args = list(args)
    603             # Indexed by order in the output

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(604)call_with_inout()
    603             # Indexed by order in the output
--> 604             outargs = {}
    605             outnum = 0

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(605)call_with_inout()
    604             outargs = {}
--> 605             outnum = 0
    606             for i, info in enumerate(paramflags):

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(606)call_with_inout()
    605             outnum = 0
--> 606             for i, info in enumerate(paramflags):
    607                 direction = info[0]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(607)call_with_inout()
    606             for i, info in enumerate(paramflags):
--> 607                 direction = info[0]
    608                 if direction & 3 == 3:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(608)call_with_inout()
    607                 direction = info[0]
--> 608                 if direction & 3 == 3:
    609                     # This is an [in, out] parameter.

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(612)call_with_inout()
    611                     # Determine name and required type of the parameter.
--> 612                     name = info[1]
    613                     # [in, out] parameters are passed as pointers,

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(615)call_with_inout()
    614                     # this is the pointed-to type:
--> 615                     atyp = argtypes[i]._type_
    616 

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(619)call_with_inout()
    618                     # keyword arg.
--> 619                     try:
    620                         try:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(620)call_with_inout()
    619                     try:
--> 620                         try:
    621                             v = args[i]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(621)call_with_inout()
    620                         try:
--> 621                             v = args[i]
    622                         except IndexError:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(631)call_with_inout()
    630                         # convert it to a ctypes type.
--> 631                         if getattr(v, "_type_", None) is atyp:
    632                             # Array of or pointer to type 'atyp' was

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(635)call_with_inout()
    634                             pass
--> 635                         elif type(atyp) is SIMPLETYPE:
    636                             # The from_param method of simple types

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(642)call_with_inout()
    641                             # in that case.
--> 642                             v = atyp(v)
    643                         else:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(646)call_with_inout()
    645                             assert not isinstance(v, BYREFTYPE)
--> 646                     outargs[outnum] = v
    647                     outnum += 1

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(647)call_with_inout()
    646                     outargs[outnum] = v
--> 647                     outnum += 1
    648                     if len(args) > i:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(648)call_with_inout()
    647                     outnum += 1
--> 648                     if len(args) > i:
    649                         args[i] = v

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(649)call_with_inout()
    648                     if len(args) > i:
--> 649                         args[i] = v
    650                     else:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(606)call_with_inout()
    605             outnum = 0
--> 606             for i, info in enumerate(paramflags):
    607                 direction = info[0]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(607)call_with_inout()
    606             for i, info in enumerate(paramflags):
--> 607                 direction = info[0]
    608                 if direction & 3 == 3:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(608)call_with_inout()
    607                 direction = info[0]
--> 608                 if direction & 3 == 3:
    609                     # This is an [in, out] parameter.

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(612)call_with_inout()
    611                     # Determine name and required type of the parameter.
--> 612                     name = info[1]
    613                     # [in, out] parameters are passed as pointers,

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(615)call_with_inout()
    614                     # this is the pointed-to type:
--> 615                     atyp = argtypes[i]._type_
    616 

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(619)call_with_inout()
    618                     # keyword arg.
--> 619                     try:
    620                         try:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(620)call_with_inout()
    619                     try:
--> 620                         try:
    621                             v = args[i]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(621)call_with_inout()
    620                         try:
--> 621                             v = args[i]
    622                         except IndexError:

ipdb> s
IndexError: list index out of range
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(621)call_with_inout()
    620                         try:
--> 621                             v = args[i]
    622                         except IndexError:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(622)call_with_inout()
    621                             v = args[i]
--> 622                         except IndexError:
    623                             v = kw[name]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(623)call_with_inout()
    622                         except IndexError:
--> 623                             v = kw[name]
    624                     except KeyError:

ipdb> s
KeyError: 'strServerLocation'
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(623)call_with_inout()
    622                         except IndexError:
--> 623                             v = kw[name]
    624                     except KeyError:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(624)call_with_inout()
    623                             v = kw[name]
--> 624                     except KeyError:
    625                         # no parameter was passed, make an empty one

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(627)call_with_inout()
    626                         # of the required type
--> 627                         v = atyp()
    628                     else:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(646)call_with_inout()
    645                             assert not isinstance(v, BYREFTYPE)
--> 646                     outargs[outnum] = v
    647                     outnum += 1

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(647)call_with_inout()
    646                     outargs[outnum] = v
--> 647                     outnum += 1
    648                     if len(args) > i:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(648)call_with_inout()
    647                     outnum += 1
--> 648                     if len(args) > i:
    649                         args[i] = v

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(651)call_with_inout()
    650                     else:
--> 651                         kw[name] = v
    652                 elif direction & 2 == 2:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(606)call_with_inout()
    605             outnum = 0
--> 606             for i, info in enumerate(paramflags):
    607                 direction = info[0]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(607)call_with_inout()
    606             for i, info in enumerate(paramflags):
--> 607                 direction = info[0]
    608                 if direction & 3 == 3:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(608)call_with_inout()
    607                 direction = info[0]
--> 608                 if direction & 3 == 3:
    609                     # This is an [in, out] parameter.

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(612)call_with_inout()
    611                     # Determine name and required type of the parameter.
--> 612                     name = info[1]
    613                     # [in, out] parameters are passed as pointers,

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(615)call_with_inout()
    614                     # this is the pointed-to type:
--> 615                     atyp = argtypes[i]._type_
    616 

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(619)call_with_inout()
    618                     # keyword arg.
--> 619                     try:
    620                         try:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(620)call_with_inout()
    619                     try:
--> 620                         try:
    621                             v = args[i]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(621)call_with_inout()
    620                         try:
--> 621                             v = args[i]
    622                         except IndexError:

ipdb> s
IndexError: list index out of range
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(621)call_with_inout()
    620                         try:
--> 621                             v = args[i]
    622                         except IndexError:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(622)call_with_inout()
    621                             v = args[i]
--> 622                         except IndexError:
    623                             v = kw[name]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(623)call_with_inout()
    622                         except IndexError:
--> 623                             v = kw[name]
    624                     except KeyError:

ipdb> s
KeyError: 'strServerName'
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(623)call_with_inout()
    622                         except IndexError:
--> 623                             v = kw[name]
    624                     except KeyError:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(624)call_with_inout()
    623                             v = kw[name]
--> 624                     except KeyError:
    625                         # no parameter was passed, make an empty one

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(627)call_with_inout()
    626                         # of the required type
--> 627                         v = atyp()
    628                     else:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(646)call_with_inout()
    645                             assert not isinstance(v, BYREFTYPE)
--> 646                     outargs[outnum] = v
    647                     outnum += 1

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(647)call_with_inout()
    646                     outargs[outnum] = v
--> 647                     outnum += 1
    648                     if len(args) > i:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(648)call_with_inout()
    647                     outnum += 1
--> 648                     if len(args) > i:
    649                         args[i] = v

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(651)call_with_inout()
    650                     else:
--> 651                         kw[name] = v
    652                 elif direction & 2 == 2:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(606)call_with_inout()
    605             outnum = 0
--> 606             for i, info in enumerate(paramflags):
    607                 direction = info[0]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(607)call_with_inout()
    606             for i, info in enumerate(paramflags):
--> 607                 direction = info[0]
    608                 if direction & 3 == 3:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(608)call_with_inout()
    607                 direction = info[0]
--> 608                 if direction & 3 == 3:
    609                     # This is an [in, out] parameter.

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(612)call_with_inout()
    611                     # Determine name and required type of the parameter.
--> 612                     name = info[1]
    613                     # [in, out] parameters are passed as pointers,

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(615)call_with_inout()
    614                     # this is the pointed-to type:
--> 615                     atyp = argtypes[i]._type_
    616 

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(619)call_with_inout()
    618                     # keyword arg.
--> 619                     try:
    620                         try:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(620)call_with_inout()
    619                     try:
--> 620                         try:
    621                             v = args[i]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(621)call_with_inout()
    620                         try:
--> 621                             v = args[i]
    622                         except IndexError:

ipdb> s
IndexError: list index out of range
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(621)call_with_inout()
    620                         try:
--> 621                             v = args[i]
    622                         except IndexError:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(622)call_with_inout()
    621                             v = args[i]
--> 622                         except IndexError:
    623                             v = kw[name]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(623)call_with_inout()
    622                         except IndexError:
--> 623                             v = kw[name]
    624                     except KeyError:

ipdb> s
KeyError: 'strOmitStart'
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(623)call_with_inout()
    622                         except IndexError:
--> 623                             v = kw[name]
    624                     except KeyError:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(624)call_with_inout()
    623                             v = kw[name]
--> 624                     except KeyError:
    625                         # no parameter was passed, make an empty one

ipdb> ss
*** NameError: name 'ss' is not defined
ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(627)call_with_inout()
    626                         # of the required type
--> 627                         v = atyp()
    628                     else:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(646)call_with_inout()
    645                             assert not isinstance(v, BYREFTYPE)
--> 646                     outargs[outnum] = v
    647                     outnum += 1

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(647)call_with_inout()
    646                     outargs[outnum] = v
--> 647                     outnum += 1
    648                     if len(args) > i:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(648)call_with_inout()
    647                     outnum += 1
--> 648                     if len(args) > i:
    649                         args[i] = v

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(651)call_with_inout()
    650                     else:
--> 651                         kw[name] = v
    652                 elif direction & 2 == 2:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(606)call_with_inout()
    605             outnum = 0
--> 606             for i, info in enumerate(paramflags):
    607                 direction = info[0]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(607)call_with_inout()
    606             for i, info in enumerate(paramflags):
--> 607                 direction = info[0]
    608                 if direction & 3 == 3:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(608)call_with_inout()
    607                 direction = info[0]
--> 608                 if direction & 3 == 3:
    609                     # This is an [in, out] parameter.

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(652)call_with_inout()
    651                         kw[name] = v
--> 652                 elif direction & 2 == 2:
    653                     outnum += 1

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(653)call_with_inout()
    652                 elif direction & 2 == 2:
--> 653                     outnum += 1
    654 

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(606)call_with_inout()
    605             outnum = 0
--> 606             for i, info in enumerate(paramflags):
    607                 direction = info[0]

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\__init__.py(655)call_with_inout()
    654 
--> 655             rescode = func(self_, *args, **kw)
    656             # If there is only a single output value, then do not expect it to

ipdb> s
--Call--
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(185)__init__()
    184 
--> 185     def __init__(self, *args):
    186         if args:

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(186)__init__()
    185     def __init__(self, *args):
--> 186         if args:
    187             self.value = args[0]

ipdb> s
--Return--
None
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(186)__init__()
    185     def __init__(self, *args):
--> 186         if args:
    187             self.value = args[0]

ipdb> s
--Call--
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(555)from_param()
    554     # examples.
--> 555     def from_param(cls, arg):
    556         # accept POINTER(VARIANT) instance

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(557)from_param()
    556         # accept POINTER(VARIANT) instance
--> 557         if isinstance(arg, POINTER(VARIANT)):
    558             return arg

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(560)from_param()
    559         # accept byref(VARIANT) instance
--> 560         if isinstance(arg, _carg_obj) and isinstance(arg._obj, VARIANT):
    561             return arg

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(563)from_param()
    562         # accept VARIANT instance
--> 563         if isinstance(arg, VARIANT):
    564             return byref(arg)

ipdb> s
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(564)from_param()
    563         if isinstance(arg, VARIANT):
--> 564             return byref(arg)
    565         if isinstance(arg, _CArrayType) and arg._type_ is VARIANT:

ipdb> s
--Return--
<cparam 'P' (0BD4DE68)>
> c:\python\anaconda3\envs\py36_32b\lib\site-packages\comtypes\automation.py(564)from_param()
    563         if isinstance(arg, VARIANT):
--> 564             return byref(arg)
    565         if isinstance(arg, _CArrayType) and arg._type_ is VARIANT:

den-run-ai avatar Dec 26 '18 21:12 den-run-ai