From chris at kateandchris.net Fri Jul 1 04:40:57 2011 From: chris at kateandchris.net (Chris Lambacher) Date: Thu, 30 Jun 2011 22:40:57 -0400 Subject: [python-win32] UnicodeEncodeError getting Query String Data from ActiveX Scripting engine in classic asp Message-ID: Hi, I am embedding python code into an existing legacy classic asp application. I need to access utf-8 encoded unicode query string data from python. I have something along the lines of (simplified): in test.asp and I use a get request to: http://localhost/test.asp?ErrMsg=La+connexion+%C3%A0+la+base+de+donn%C3%A9es+a+%C3%A9chou%C3%A9 If I run the the raw query parameter through urllib.unquote_plus, I get a correctly utf-8 encoded string. If I attempt to get a python unicode object I get: Python ActiveX Scripting Engine error '80020009' Traceback (most recent call last): File " Maybe there should be a __unicode__ method on the class? Maybe __str__ should set an explicit encoding? Something like: def __unicode__(self): try: return unicode(self.__call__()) except pythoncom.com_error, details: if details.hresult not in ERRORS_BAD_CONTEXT: raise return self.__repr__() def __str__(self): return unicode(self).encode('utf-8') __unicode__ was introduced in python 2.2 and therefore is supported by every 2.x version of python that a build is provided for on sourceforge download page. -Chris On Thu, Jun 30, 2011 at 10:40 PM, Chris Lambacher wrote: > Hi, > > I am embedding python code into an existing legacy classic asp > application. I need to access utf-8 encoded unicode query string data > from python. > > I have something along the lines of (simplified): > > > > in test.asp and I use a get request to: > > http://localhost/test.asp?ErrMsg=La+connexion+%C3%A0+la+base+de+donn%C3%A9es+a+%C3%A9chou%C3%A9 > > If I run the the raw query parameter through urllib.unquote_plus, I > get a correctly utf-8 encoded string. If I attempt to get a python > unicode object I get: > Python ActiveX Scripting Engine error '80020009' > > Traceback (most recent call last): File "