[Tutor] Beautiful Soup / Unicode problem?

grouchy grouch at gmail.com
Fri Aug 26 18:08:34 CEST 2005

Hi Danny,

> If you have a moment, do you mind doing this on your system?

Here you go:

>>> import types
>>> print types.StringTypes
(<type 'str'>, <type 'unicode'>)
>>> import sys
>>> print sys.version
2.3.4 (#2, May 29 2004, 03:31:27)
[GCC 3.3.3 (Debian 20040417)]
>>> print type(u'hello' in types.StringTypes

I have a second machine running XP and Activestate 2.4.1, I get the
same results with the exception of:

>>> sys.version
'2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)]'

Today I tried changing my default encoding to uft8, and the error went
away.  I have no idea -why- it would go away, and it feels like a
hacky solution.  And confusing, because I wasn't trying to print
anything to the screen, so why would python care or complain?

Almost forgot, I tried the included Beautiful Soup tests on both
machines and got an error on both:

# python BeautifulSoupTests.py
ERROR: testBasicUnicode (__main__.UnicodeRed)
Traceback (most recent call last):
  File "BeautifulSoupTests.py", line 209, in testBasicUnicode
    self.assertEqual(type(str(self.soup)), sType)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc8' in
position 13: ordinal not in range(128)

So there may be a bug, but I don't know if it's my problem  It's
strange that the tests fail on two different computers running two
versions of python, however.

> and show us what comes up?
> Good luck to you!

More information about the Tutor mailing list