4

Using OS X 10.6.8, libxml 2-2.7.8, libxslt-1.1.26, and python 2.6, I'm trying to run the tumblrRestore.py script linked here:

https://github.com/hughsaunders/Tumblr-Restore/blob/master/tumblrRestore.py

It ran successfully and restored 76 posts before crashing.

However on second run I got an ExpatError: no element found, and have not been able to run it successfully since - it always produces this same error now. Error text:

Tumblr Restore
Traceback (most recent call last):
File "tumblrRestore.py", line 264, in <module>
cli.start()
File "tumblrRestore.py", line 232, in start
bp.parse()
File "tumblrRestore.py", line 51, in parse
postelement=ElementTree.fromstring(xml_string)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/etree/ElementTree.py", line 964, in XM
return parser.close()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/etree/ElementTree.py", line 1254, in close
self._parser.Parse("", 1) # end of data
xml.parsers.expat.ExpatError: no element found: line 1, column 0

I'm wondering whether I have the wrong or competing or outdated versions of python or lxml, though that still doesn't explain why the script ran successfully once.

Complete newbie, any advice appreciated.

mzjn
  • 48,958
  • 13
  • 128
  • 248
user1395079
  • 41
  • 1
  • 2
  • 1
    check the encoding of your file. maybe you have a BOM mark or something ugly in it. The error message sounds like it is not happy with the very first character in `xml_string`. – Daren Thomas May 15 '12 at 14:48
  • Thanks, I tried receiving as Unicode UTF-8 no BOM, but am still getting exactly the same error. Also I'm still wondering why it ran correctly the first time but won't on subsequent occurrences? – user1395079 May 17 '12 at 00:35

1 Answers1

0

Check your extract_xml_string method of BackupParser class. It definitely returns empty string, because your begin_re regular expresssion doesn't match xml header.

Try the next one:

begin_re = re.compile("<\? xml .*\?>")
Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62