python - Django XML failed to load external entity -


i'm receiving param called xml contains xml document. have tried...

from lxml.cssselect import cssselector, etree lxml.etree import fromstring  if request.post:      parser = etree.xmlparser(ns_clean=true, recover=true)     h = etree.parse(request.post['xml'], parser)      return httpresponse(h) 

but i'm getting error:

[fri apr 05 09:50:13 2013] [error] ioerror: error reading file '<?xml version="1.0" encoding="iso-8859-1"?> [fri apr 05 09:50:13 2013] [error] <delivery_receipt> [fri apr 05 09:50:13 2013] [error]     <version>1.1</version> [fri apr 05 09:50:13 2013] [error]     <msisdn>447777111111</msisdn> [fri apr 05 09:50:13 2013] [error]     <submission_ref>12345678901234567890123456789012</submission_ref> [fri apr 05 09:50:13 2013] [error]     <status>delivered</status> [fri apr 05 09:50:13 2013] [error]     <reason>4</reason> [fri apr 05 09:50:13 2013] [error]     <gmt_timestamp>20130405095100</gmt_timestamp> [fri apr 05 09:50:13 2013] [error]     <retry>0</retry> [fri apr 05 09:50:13 2013] [error] </delivery_receipt>': failed load external entity "<?xml version="1.0" encoding="iso-8859-1"?> [fri apr 05 09:50:13 2013] [error] <delivery_receipt> [fri apr 05 09:50:13 2013] [error]     <version>1.1</version> [fri apr 05 09:50:13 2013] [error]     <msisdn>447777111111</msisdn> [fri apr 05 09:50:13 2013] [error]     <submission_ref>12345678901234567890123456789012</submission_ref> 

etc

any ideas? :)

request.post returns unicode strings default. next problem having related encoding supplying isn't matching declared encoding in document you're supplying.

doc = request.post.get('xml','') if not doc:   raise exception() h = etree.xml(doc.encode('ascii'), parser) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -