brian herman wrote at 2015-6-5 10:39 -0500: >I have a python application that uses pysimplesoap to send a soap >request to windows.
This is not an SOAP question; it is a question about charset encodings. >The problem is the password field is not encoded in UTF-8 it may use >Windows-1252? >Python Code >https://gist.github.com/brianherman/209af7751444ec308e1b >Visual Basic Sample code (how to encode the password field in visual basic) >https://gist.github.com/brianherman/b4174b99be9000fcc4f8 The names used in the "Visual Basic" code indicate that the password comes from an UI widget (a "text box"). Check in the UI toolkit documentation) which type (unicode or encode string) and (in the second case) which encoding the "Text" field uses. In the "Visual Basic" code, the "GetBytes" method of an "ASCIIEncoding" is applied to this value. The will transform the password value into a sequences of bytes (which is then hashed via "MD5"). Check the documentation of "ASCIIEncoding.GetBytes" to learn what it really does. It is this effect you will need to reproduce in Python (provided your Python program gets the password in the same type and the encoding). After you have got in your Python program the password as a sequence of bytes (emulating potentially a transformation to the type/encoding of the "Visual Basic" and then the effect of "ASCIIEncoding.GetBytes), you can apply Python's "md5" transformation ("import md5; hasher = md5.new(password); password_hash = hasher.digest()"). The "Visual Basic" code then uses the "ASCIIEncoding" again to convert the sequence of bytes into a "String". This likely means: 1. "String" corresponds to Python's "unicode" ("str" in Python 3) 2. "ASCIIEncoding" is badly named; it likely is in fact the "iso-8859-1" encoding (known to Python under this name). If this assumption is correct, then * you should get the "password" value as type "unicode" * you can use "password.encode('iso-8859-1')" to get the effect of "ASCIIEncoding.GetBytes(password)" * you can use "password_hash.decode('iso-8859-1')" to get the effect of "ASCIIEncoding.GetString(password_hash)". You must consult your documentation to check whether the assumptions are correct. _______________________________________________ Soap mailing list [email protected] https://mail.python.org/mailman/listinfo/soap
