title: Is there an easy way to make unicode work in python?
body: <p>I'm trying to deal with unicode in python 2.7.2. I know there is the <code>.encode('utf-8')</code> thing but 1/2 the time when I add it, I get errors, and 1/2 the time when I don't add it I get errors. </p>
  
  <p>Is there any way to tell python - what I thought was an up-to-date &amp; modern language to just use unicode for strings and not make me have to fart around with <code>.encode('utf-8')</code> stuff?</p>
  
  <p>I know... python 3.0 is supposed to do this, but I can't use 3.0 and 2.7 isn't all that old anyways...</p>
  
  <p>For example:</p>
  
  <pre><code>url = "http://en.wikipedia.org//w/api.php?action=query&amp;list=search&amp;format=json&amp;srlimit=" + str(items) + "&amp;srsearch=" + urllib2.quote(title.encode('utf-8'))
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 19: ordinal not in range(128)
  </code></pre>
  
  <p><strong>Update</strong>
  If I remove all my <code>.encode</code> statements from all my code and add <code># -*- coding: utf-8 -*-</code> to the top of my file, right under the <code>#!/usr/bin/python</code> then I get the following, same as if I didn't add the <code># -*- coding: utf-8 -*-</code> at all.</p>
  
  <pre><code>/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py:1250: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
    return ''.join(map(quoter, s))
  Traceback (most recent call last):
    File "classes.py", line 583, in &lt;module&gt;
      wiki.getPage(title)
    File "classes.py", line 146, in getPage
      url = "http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;format=json&amp;rvprop=content&amp;rvlimit=1&amp;titles=" + urllib2.quote(title)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1250, in quote
      return ''.join(map(quoter, s))
  KeyError: u'\xf1'
  </code></pre>
  
  <p>I'm not manually typing in any string, I parsing HTML and json from websites. So the scripts/bytestreams/whatever they are, are all created by python.</p>
  
  <p><strong>Update 2</strong> I can move the error along, but it just keeps coming up in new places. I was hoping python would be a useful scripting tool, but looks like after 3 days of no luck I'll just try a different language. Its a shame, python is preinstalled on osx. I've marked correct the answer that fixed the one instance of the error I posted.</p>