title: UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026'
body: <p>I'm learning about urllib2 and Beautiful Soup and on first tests am getting errors like:</p>
  
  <pre><code>UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 10: ordinal not in range(128)
  </code></pre>
  
  <p>There seem to be lots of posts about this type of error and I have tried the solutions that I can understand but there seem to be catch 22's with them, e.g.:</p>
  
  <p>I want to print <code>post.text</code> (where text is a beautiful soup method that just returns the text).
  <code>str(post.text)</code> and <code>post.text</code> produce the unicode errors (on things like right apostrophe's <code>'</code> and <code>...</code>).  </p>
  
  <p>So I add <code>post = unicode(post)</code> above <code>str(post.text)</code>, then I get:</p>
  
  <pre><code>AttributeError: 'unicode' object has no attribute 'text'
  </code></pre>
  
  <p>I also tried <code>(post.text).encode()</code> and <code>(post.text).renderContents()</code>. 
  The latter producing the error:</p>
  
  <pre><code>AttributeError: 'unicode' object has no attribute 'renderContents'
  </code></pre>
  
  <p>and then I tried <code>str(post.text).renderContents()</code> and got the error:</p>
  
  <pre><code>AttributeError: 'str' object has no attribute 'renderContents'
  </code></pre>
  
  <p>It would be great if I could just define somewhere at the top of the document <code>'make this content 'interpretable''</code> and still have access to the required <code>text</code> function.  </p>
  
  <hr>
  
  <p><strong>Update:</strong>  after suggestions:  </p>
  
  <p>If I add <code>post = post.decode("utf-8")</code> above <code>str(post.text)</code> I get:</p>
  
  <pre><code>TypeError: unsupported operand type(s) for -: 'str' and 'int'  
  </code></pre>
  
  <p>If I add <code>post = post.decode()</code> above <code>str(post.text)</code> I get:</p>
  
  <pre><code>AttributeError: 'unicode' object has no attribute 'text'
  </code></pre>
  
  <p>If I add <code>post = post.encode("utf-8")</code> above <code>(post.text)</code> I get:</p>
  
  <pre><code>AttributeError: 'str' object has no attribute 'text'
  </code></pre>
  
  <p>I tried <code>print post.text.encode('utf-8')</code> and got:</p>
  
  <pre><code>UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 39: ordinal not in range(128)
  </code></pre>
  
  <p>And for the sake of trying things that might work, I installed lxml for Windows from <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml" rel="noreferrer">here</a> and implemented it with:</p>
  
  <pre><code>parsed_content = BeautifulSoup(original_content, "lxml")
  </code></pre>
  
  <p>according to <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/#output-formatters" rel="noreferrer">http://www.crummy.com/software/BeautifulSoup/bs4/doc/#output-formatters</a>.</p>
  
  <p>These steps didn't seem to make a difference.  </p>
  
  <p>I'm using Python 2.7.4 and Beautiful Soup 4.  </p>
  
  <hr>
  
  <p><strong>Solution:</strong></p>
  
  <p>After getting a deeper understanding of unicode, utf-8 and Beautiful Soup types, it had something to do with my printing methodology. I removed all my <code>str</code> methods and concatenations, e.g. <code>str(something) + post.text + str(something_else)</code>, so that it was <code>something, post.text, something_else</code> and it seems to be printing well except I have less control of the formatting at this stage (e.g. spaces inserted at <code>,</code>). </p>