broom9 / live-space-mover

Automatically exported from code.google.com/p/live-space-mover
0 stars 0 forks source link

TypeError: coercing to Unicode: need string or buffer, Tag found #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. environment: Python 2.6.4, BeautifulSoup 3.0.8
2. set the date format correctly
3. type command python live-space-mover.py -s
http://nothing4something.spaces.live.
com/ -t "%m/%d/%Y %I:%M:%S %p". Without -t option, the problem was the same.

What is the expected output? What do you see instead?

blog entries should be exported successfully. But after found the 1st
Permaink, Below errors came across:
LINE 564  : ERROR    Unexpected error
Traceback (most recent call last):
  File "live-space-mover.py", line 562, in <module>
    main()
  File "live-space-mover.py", line 485, in main
    i=fetchEntry(permalink,datetimepattern,mode)
  File "live-space-mover.py", line 127, in fetchEntry
    i['content']=u''.join(map(CData,temp.contents))
  File "D:\livespace\BeautifulSoup.py", line 435, in __new__
    return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING)
TypeError: coercing to Unicode: need string or buffer, Tag found
Traceback (most recent call last):
  File "live-space-mover.py", line 562, in <module>
    main()
  File "live-space-mover.py", line 485, in main
    i=fetchEntry(permalink,datetimepattern,mode)
  File "live-space-mover.py", line 127, in fetchEntry
    i['content']=u''.join(map(CData,temp.contents))
  File "D:\livespace\BeautifulSoup.py", line 435, in __new__
    return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING)
TypeError: coercing to Unicode: need string or buffer, Tag found

What version of the product are you using? On what operating system?
v1.7.6 in WindowsXP

Please provide any additional information below.

Original issue reported on code.google.com by wangxiao...@gmail.com on 11 Jan 2010 at 2:53

GoogleCodeExporter commented 9 years ago
plz help to delete this issue or remove my blog address...
This problem is caused by using new Python/BeautifulSoup. Using Python 2.5.4 &
Beautiful Soup 3.0.6 works fine.

Original comment by wangxiao...@gmail.com on 11 Jan 2010 at 4:23

GoogleCodeExporter commented 9 years ago
Change the __new__ method for NavigableString in Beautiful Soup can fix this:   

    def __new__(cls, value):
        """Create a new NavigableString.

        When unpickling a NavigableString, this method is called with
        the string in DEFAULT_OUTPUT_ENCODING. That encoding needs to be
        passed in to the superclass's __new__ or the superclass won't know
        how to handle non-ASCII characters.
        """
        if isinstance(value, unicode):
            return unicode.__new__(cls, value)
        elif isinstance(value, Tag):
            print value
            return unicode.__new__(cls, value.__str__(), DEFAULT_OUTPUT_ENCODING)
        else:
            return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING)

Original comment by robert.z...@gmail.com on 28 Sep 2010 at 2:57

GoogleCodeExporter commented 9 years ago
oops, that "print value" is for debugging, you should remove it.

Original comment by robert.z...@gmail.com on 28 Sep 2010 at 2:58