Python GetModule中的comtypes错误:UnicodeDecodeError:'utf-8'编解码器无法解码位置621处的字节0x92:无效的起始字节

问题描述

我正在Python中使用comtypes包的GetModule。 我得到错误 UnicodeDecodeError:'utf-8'编解码器无法解码位置621处的字节0x92:无效的起始字节

Below the details: 
---------------------------------------------------------------------------
SyntaxError                               Traceback (most recent call last)
    [... skipping hidden 1 frame]

<ipython-input-5-3a53f2c64cb1> in <module>
----> 1 GetModule("C:\\Program Files (x86)\\xxxxxxxxxxxx.exe")

~\Anaconda3\lib\site-packages\comtypes\client\_generate.py in GetModule(tlib)
    109     # create and import the module
--> 110     mod = _CreateWrapper(tlib,pathname)
    111     try:

~\Anaconda3\lib\site-packages\comtypes\client\_generate.py in _CreateWrapper(tlib,pathname)
    171     logger.info("# Generating comtypes.gen.%s",modname)
--> 172     generate_module(tlib,ofi,pathname)
    173 

~\Anaconda3\lib\site-packages\comtypes\tools\tlbparser.py in generate_module(tlib,pathname)
    749 
--> 750     gen.generate_code(list(items.values()),filename=pathname)
    751 

~\Anaconda3\lib\site-packages\comtypes\tools\codegenerator.py in generate_code(self,items,filename)
    240             self.more = set()
--> 241             self.generate_all(items)
    242 

~\Anaconda3\lib\site-packages\comtypes\tools\codegenerator.py in generate_all(self,items)
    188         for item in items:
--> 189             self.generate(item)
    190 

~\Anaconda3\lib\site-packages\comtypes\tools\codegenerator.py in generate(self,item)
    184         self.done.add(item)
--> 185         mth(item)
    186 

~\Anaconda3\lib\site-packages\comtypes\tools\codegenerator.py in External(self,ext)
    628         print("import",modname,file=self.imports)
--> 629         comtypes.client.GetModule(ext.tlib)
    630 

~\Anaconda3\lib\site-packages\comtypes\client\_generate.py in GetModule(tlib)
    109     # create and import the module
--> 110     mod = _CreateWrapper(tlib,pathname)
    183         ofi.close()
--> 184         mod = _my_import(fullname)
    185     return mod

~\Anaconda3\lib\site-packages\comtypes\client\_generate.py in _my_import(fullname)
     23         comtypes.gen.__path__.append(comtypes.client.gen_dir)
---> 24     return __import__(fullname,globals(),locals(),['DUMMY'])
     25 

SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0x92 in position 51: invalid start byte (_EA544A21_C82D_11D1_A3E4_00A0C90AEA82_9_6_0.py,line 1414)

During handling of the above exception,another exception occurred:

UnicodeDecodeError                        Traceback (most recent call last)
    [... skipping hidden 1 frame]

~\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in showtraceback(self,exc_tuple,filename,tb_offset,exception_only,running_compiled_code)
   2028                 # Though this won't be called by Syntax errors in the input
   2029                 # line,there may be SyntaxError cases with imported code.
-> 2030                 self.showSyntaxerror(filename,running_compiled_code)
   2031             elif etype is UsageError:
   2032                 self.show_usage_error(value)

~\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in showSyntaxerror(self,running_compiled_code)
   2090         # If the error occurred when executing compiled code,we should provide full stacktrace.
   2091         elist = traceback.extract_tb(last_traceback) if running_compiled_code else []
-> 2092         stb = self.SyntaxTB.structured_traceback(etype,value,elist)
   2093         self._showtraceback(etype,stb)
   2094 

~\Anaconda3\lib\site-packages\IPython\core\ultratb.py in structured_traceback(self,etype,elist,context)
   1469                 and isinstance(value.lineno,int):
   1470             linecache.checkcache(value.filename)
-> 1471             newtext = linecache.getline(value.filename,value.lineno)
   1472             if newtext:
   1473                 value.text = newtext

~\Anaconda3\lib\linecache.py in getline(filename,lineno,module_globals)
     14 
     15 def getline(filename,module_globals=None):
---> 16     lines = getlines(filename,module_globals)
     17     if 1 <= lineno <= len(lines):
     18         return lines[lineno-1]

~\Anaconda3\lib\linecache.py in getlines(filename,module_globals)
     45 
     46     try:
---> 47         return updatecache(filename,module_globals)
     48     except MemoryError:
     49         clearcache()

~\Anaconda3\lib\linecache.py in updatecache(filename,module_globals)
    135     try:
    136         with tokenize.open(fullname) as fp:
--> 137             lines = fp.readlines()
    138     except OSError:
    139         return []

~\Anaconda3\lib\codecs.py in decode(self,input,final)
    320         # decode input (taking the buffer into account)
    321         data = self.buffer + input
--> 322         (result,consumed) = self._buffer_decode(data,self.errors,final)
    323         # keep undecoded input until the next call
    324         self.buffer = data[consumed:]

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 621: invalid start byte

我对Python很陌生。我搜索了其他一些有关编码的解决方案,他们建议在读取函数添加“ encoding = xxx”,但我不知道如何在comtypes包中找到“读取”函数。 有人有什么建议吗? 非常感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)