Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It doesn't look like Python is "reading it in UTF-8" at all. As already pointed out, you have an encoding problem, NOT a decoding problem. It is impossible for that error to have arisen from that line that you say. When asking a question like this, always give the full traceback and error message.</p> <p>Kathy's suspicion is correct; in fact the <code>print str</code> line is the only possible source of that error, and that can only happen when sys.stdout.encoding is not set so Python punts on 'ascii'.</p> <p>Variables that may affect the outcome are what version of Python you are using, what platform you are running on and exactly how you run your script -- none of which you have told us; please do.</p> <p>Example: I'm using Python 2.6.2 on Windows XP and I'm running your script with some diagnostic additions: (1) <code>import sys; print sys.stdout.encoding</code> up near the front (2) <code>print repr(str)</code> before <code>print str</code> so that I can see what you've got before it crashes.</p> <p>In a Command Prompt window, if I do <code>\python26\python hockey.py</code> it prints <code>cp850</code> as the encoding and just works.</p> <p>However if I do</p> <pre><code>\python26\python hockey.py | more </code></pre> <p>or</p> <pre><code>\python26\python hockey.py &gt;hockey.txt </code></pre> <p>it prints <code>None</code> as the encoding and crashes with your error message on the first line with the a-with-diaeresis:</p> <pre><code>C:\junk&gt;\python26\python hockey.py &gt;hockey.txt Traceback (most recent call last): File "hockey.py", line 18, in &lt;module&gt; print str UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 2: ordinal not in range(128) </code></pre> <p>If that fits your case, the fix in general is to explicitly encode your output with an encoding suited to the display mechanism you plan to use.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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