Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The reason for the behaviour you observed is that <code>from __future__ import unicode_literals</code> switches the way Python works with strings:</p> <ul> <li>In the 2.x series, strings without the <em>u</em> prefix are treated as sequences of bytes, each of which may be in the range \x00-\xff (inclusive). Strings with the <em>u</em> prefix are ucs-2 encoded unicode sequences.</li> <li>In Python 3.x -- as well as in the <code>unicode_literals</code> future, strings without the <em>u</em> prefix are unicode strings encoded in either UCS-2 or UCS-4 (depends on the compiler flag used when compiling Python). Strings with the <em>b</em> prefix are literals for the data type <code>bytes</code> which are rather similar to pre-3.x non-unicode strings.</li> </ul> <p>In either version of Python, byte-strings and unicode-strings must be converted. The conversion performed by default depends on your system's default charset; in your case this is <em>UTF-8</em>. Without setting anything, it should be <em>ascii</em>, which rejects all characters above \x7f.</p> <p>The message digest returned by hashlib.md5(...).digest() is a bytes-string, and I suppose you want the result of the whole operation to be a byte-string as well. If you want that, convert the nonce and cnonce-strings to byte-strings.:</p> <pre><code>a1 = hashlib.md5("%s:%s:%s" % (self.username, self.domain, self.password)).digest() # note that UTF-8 may not be the encoding required by your counterpart, please check a1 = b"%s:%s:%s" %(a1, challenge["nonce"].encode("UTF-8"), cnonce.encode("UTF-8") ) </code></pre> <p>Alternatively, you can convert the byte-string coming from the call to <code>digest()</code> to a unicode string (not recommended). As the lower 8 bit of UCS-2 are equivalent to ISO-8859-1, this might serve your needs:</p> <pre><code>a1 = hashlib.md5("%s:%s:%s" % (self.username, self.domain, self.password)).digest() a1 = "%s:%s:%s" %(a1.decode("ISO-8859-1"), challenge["nonce"], cnonce) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload