Python UnicodeDecodeError在SUDS中,但仅在py2exe生成的.exe中

Python UnicodeDecodeError在SUDS中,但仅在py2exe生成的.exe中,python,character-encoding,ascii,py2exe,suds,Python,Character Encoding,Ascii,Py2exe,Suds,我有一个Python 2.7脚本sendprord.py,它使用sud与web服务通信。在脚本中,我调用了一个web服务方法,该方法将一些参数作为字符串runJobpar1、par2、par3传递。它可以很好地处理字符串中的西欧字符。我用PyDev在Eclipse中运行它 然后我使用py2exe生成.exe。现在它给了我一个错误 Traceback (most recent call last): File "SendPreord.py", line 80, in <module>

我有一个Python 2.7脚本sendprord.py,它使用sud与web服务通信。在脚本中,我调用了一个web服务方法,该方法将一些参数作为字符串runJobpar1、par2、par3传递。它可以很好地处理字符串中的西欧字符。我用PyDev在Eclipse中运行它

然后我使用py2exe生成.exe。现在它给了我一个错误

Traceback (most recent call last):
  File "SendPreord.py", line 80, in <module>
  File "suds\client.pyc", line 542, in __call__
  File "suds\client.pyc", line 602, in invoke
  File "suds\client.pyc", line 637, in send
  File "suds\transport\https.pyc", line 64, in send
  File "suds\transport\http.pyc", line 77, in send
  File "suds\transport\http.pyc", line 118, in u2open
  File "urllib2.pyc", line 391, in open
  File "urllib2.pyc", line 409, in _open
  File "urllib2.pyc", line 369, in _call_chain
  File "urllib2.pyc", line 1173, in http_open
  File "urllib2.pyc", line 1142, in do_open
  File "httplib.pyc", line 946, in request
  File "httplib.pyc", line 987, in _send_request
  File "httplib.pyc", line 940, in endheaders
  File "httplib.pyc", line 801, in _send_output
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 484: ordinal not in range(128)
通过调查,我意识到删除像èòá这样的字符可以解决问题。。。但我不能!我必须保留我传递的字符串

所以我试着在传递字符串之前解码它们:

result = ws_client.service.runJob(par1.decode('latin9'), par2.decode('latin9'), par3.decode('latin9'))
同样,所有文件都可以在.py中工作,但不能在.exe中工作。也许PyDev会以某种方式纠正这个问题

附件

Setup.py:

from distutils.core import setup
import py2exe
setup(console=['src/SendPreord.py'])
py2exe输出日志的有趣摘录:

*** copy dlls ***
copying C:\Python27\lib\site-packages\py2exe\run.exe -> C:\Users\xxxxxxx\workspace\eclipse\SendPreord\dist\SendPreord.exe
The following modules appear to be missing
['ElementC14N', '_scproxy', 'ntlm']

*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.

Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.

   USER32.dll - C:\Windows\system32\USER32.dll
   SHELL32.dll - C:\Windows\system32\SHELL32.dll
   WSOCK32.dll - C:\Windows\system32\WSOCK32.dll
   ADVAPI32.dll - C:\Windows\system32\ADVAPI32.dll
   WS2_32.dll - C:\Windows\system32\WS2_32.dll
   KERNEL32.dll - C:\Windows\system32\KERNEL32.dll

你已经被Python对编码转换的猜测所困扰。您尝试的第一部分是正确的:首先使用希望正确的编码进行解码。在你发出之前,你必须
再次编码,最好使用UTF-8之类的东西,否则Python会尝试默认编码,这在大多数ASCII安装中都是如此

你已经被Python对编码转换的猜测给咬了一口。您尝试的第一部分是正确的:首先使用希望正确的编码进行解码。在你发出之前,你必须 再次编码,最好使用UTF-8之类的东西,否则Python会尝试默认编码,这在大多数ASCII安装中都是如此

*** copy dlls ***
copying C:\Python27\lib\site-packages\py2exe\run.exe -> C:\Users\xxxxxxx\workspace\eclipse\SendPreord\dist\SendPreord.exe
The following modules appear to be missing
['ElementC14N', '_scproxy', 'ntlm']

*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.

Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.

   USER32.dll - C:\Windows\system32\USER32.dll
   SHELL32.dll - C:\Windows\system32\SHELL32.dll
   WSOCK32.dll - C:\Windows\system32\WSOCK32.dll
   ADVAPI32.dll - C:\Windows\system32\ADVAPI32.dll
   WS2_32.dll - C:\Windows\system32\WS2_32.dll
   KERNEL32.dll - C:\Windows\system32\KERNEL32.dll