1

The following code is from 'Python for Data Analysis':

from io import StringIO
import io

tag = '<a href="http://www.google.com">Google</a>'
root = objectify.parse(io.StringIO(tag).getroot())

Executing the code produces the following error:

TypeError: initial_value must be unicode or None, not str

Please help!

stickfigure
  • 13,458
  • 5
  • 34
  • 50
RichV
  • 33
  • 1
  • 4

1 Answers1

0

StringIO expects a unicode string which is not the default kind of string in python 2. Replacing

tag = '<a href="http://www.google.com">Google</a>'

with

tag = u'<a href="http://www.google.com">Google</a>'

should work.

merlyn
  • 2,273
  • 1
  • 19
  • 26