1

Here's the Python source:

fsock = urllib2.urlopen('http://eprints.soton.ac.uk/cgi/exportview/divisions/uos-fp/2009/XML/uos-fp_2009.xml')

doc=et.parse(fsock)

When I tried to run this it gives the following error:

Traceback (most recent call last):
  File "C:\Python27\reading and writing xml file from web1.py", line 30, in 
    doc=et.parse(fsock)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1176, in parse
    tree.parse(source, parser)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 654, in parse
    self._root = parser.close()
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1635, in close
    self._raiseerror(v)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1487, in _raiseerror
    raise err
ParseError: no element found: line 1, column 0

Can any one help as to why this is happening?

3
  • Post your real code. What you have works for me. Commented Apr 12, 2011 at 20:52
  • Can you actually open that URL in a browser and retrieve the XML? The error sounds like a premature EOF on the input stream when executing et.parse(). Commented Apr 12, 2011 at 20:54
  • The code works: import urllib2 from xml.etree.cElementTree import parse, dump fsock = urllib2.urlopen('eprints.soton.ac.uk/cgi/exportview/divisions/uos-fp/2009/XML/…) doc = parse(fsock) dump(doc) Commented Apr 12, 2011 at 21:04

1 Answer 1

0

Your code works:

import urllib2  
from xml.etree.cElementTree import parse, dump  

fsock = urllib2.urlopen('http://eprints.soton.ac.uk/cgi/exportview/divisions/uos-fp/2009/XML/uos-fp_2009.xml')

doc = parse(fsock)  
dump(doc)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it works but it seems that it would never stop, sort of infinite iteration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.