<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dw="https://www.dreamwidth.org">
  <id>tag:dreamwidth.org,2009-04-21:107589</id>
  <title>Tang's DW</title>
  <subtitle>tangaroa</subtitle>
  <author>
    <name>tangaroa</name>
  </author>
  <link rel="alternate" type="text/html" href="https://tangaroa.dreamwidth.org/"/>
  <link rel="self" type="text/xml" href="https://tangaroa.dreamwidth.org/data/atom"/>
  <updated>2014-03-23T16:54:13Z</updated>
  <dw:journal username="tangaroa" type="personal"/>
  <entry>
    <id>tag:dreamwidth.org,2009-04-21:107589:69279</id>
    <link rel="alternate" type="text/html" href="https://tangaroa.dreamwidth.org/69279.html"/>
    <link rel="self" type="text/xml" href="https://tangaroa.dreamwidth.org/data/atom/?itemid=69279"/>
    <title>Obscure bug of the nonce</title>
    <published>2014-03-23T13:44:38Z</published>
    <updated>2014-03-23T16:54:13Z</updated>
    <category term="python"/>
    <category term="programming"/>
    <category term="xml"/>
    <category term="debugging"/>
    <category term="i18n"/>
    <category term="computers"/>
    <dw:security>public</dw:security>
    <dw:reply-count>0</dw:reply-count>
    <content type="html">Python easy_install on Windows sometimes fails with a UnicodeDecodeError:

&lt;blockquote&gt;
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6034: ordinal not in range(128)
&lt;/blockquote&gt;

&lt;a href="http://stackoverflow.com/questions/19536068/mitmproxy-installation-by-the-python-setuptools-easy-install-got-error-decoding"&gt;The solution is to comment out the &lt;code&gt;config = config.decode('ascii')&lt;/code&gt; line in Lib/site-packages/setuptools/easy_install.py&lt;/a&gt;.

&lt;hr /&gt;

&lt;p&gt;Here's an even more fun one: 

&lt;blockquote&gt;&lt;pre&gt;
  File "geopts.py", line 128, in xp2str
    s = etree.tostring(resultset[0], method="text")
  File "lxml.etree.pyx", line 3165, in lxml.etree.tostring (src\lxml\lxml.etree.
c:69399)

exceptions.TypeError: Type '_ElementStringResult' cannot be serialized.
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;This says that the XML library's own tostring() function cannot convert one of its own string types to a string. What's especially brilliant about this is that &lt;a href="http://lxml.de/2.1/api/lxml.etree._ElementStringResult-class.html"&gt;_ElementStringResult inherits from the native string class&lt;/a&gt;. 

&lt;p&gt;Here is a hacky attempt to manage the problem:

&lt;blockquote&gt;&lt;pre&gt;
r = resultset[0]
if isinstance(r, etree._ElementStringResult):
    s = r
else:
    s = etree.tostring(r, method="text")

&lt;/pre&gt;&lt;/blockquote&gt;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=tangaroa&amp;ditemid=69279" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
</feed>
