enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.
Other
292 stars 97 forks source link

UnicodeDecodeError: #12

Open cfarrow opened 10 years ago

cfarrow commented 10 years ago

I try Autodesk MAYA 2008 windows operate from IE 7.0 use comtypes "CreateObject". ex. Click "openImageFile"

  1. IE (Maya.CommandEngine.MEL)
  2. MAYA (melCommand "python")
  3. comtypes ( CreateObject("Photoshop.Application") ) open imageFile on PhotoShop.
1.------ test.html ------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script type="text/vbscript">
<!--
Dim MEL
Set MEL = CreateObject("Maya.CommandEngine.MEL")
MEL.Connect()
//-->
</script>
</head>
<body>
<p><a href="#" title="open" onclick="MEL.Execute('nh_execPyTest')">openImageFile</a></p>
</body>
</html>
2.------ nh_execPyTest.mel ------
global proc nh_execPyTest(){
python("nh_openPSD2()");
}
3. ------ nh_openPSD2.py ------
from comtypes.client import CreateObject
def nh_openPSD2():
try:
psApp = CreateObject("Photoshop.Application")
docRef = psApp.Open(<IMAGEPATH>)
except Exception, x:
print x
====== ERROR ======
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "C:\Documents and Settings\hatori\My Documents\maya\7.0\scripts\opt\et1.py", line 32, in nh_openPSD2
# psApp = CreateObject("Photoshop.Application")
# File "C:\Python25\Lib\site-packages\comtypes\client\__init__.py", line 197, in CreateObject
# obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
# File "C:\Python25\Lib\site-packages\comtypes\__init__.py", line 1119, in CoCreateInstance
# _ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
# File "..\Modules\_ctypes\callproc.c", line 754, in GetResult
# WindowsError: (-2147417843, '\x83A\x83v\x83......') #
...... is
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 20: ordinal not in range(128)
=====================

--- sitecustomize.py --- import sys sys.setdefaultencoding('utf-8') and win32com http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html was error. nh_execPyTest.mel and nh_openPSD2.py is operating. Could advice be got?

cfarrow commented 10 years ago

Migrated from https://sourceforge.net/p/comtypes/bugs/13/.