some weeks ago I programmed a Python script which posted some content to a Wordpress blog, but since the past week it stopped working (I haven't changed anything) and now when I run the script I get this error:
File "C:\Python27\lib\xmlrpclib.py", line 557, in feed
self._parser.Parse(data, 0)
ExpatError: junk after document element: line 2, column 0
The function I use to post the desired content to Wordpress is this:
post_id = server.wp.newPost(blog_id, user, passw, content)
and it used to work since it started crashing for (apparently) no reason.
¿Do you now what could be the cause of this error?¿Might my Wordpress have been infected (I've checked it)?
Thanks, if you need more code to check something I'll post it, and sorry for my poor English.
Important Edit:
I didn't mention that before, but the script works perfect with other wordpress blogs, it only crashes when I try to post to the WP blog I made the script for (that's why I think it the site may be infected).
When the code works the variable data used in self._parser.Parse(data, 0) has this content:
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<string>90</string>
</value>
</param>
</params>
</methodResponse>
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<int>90</int>
</value>
</param>
</params>
</methodResponse>
Edit:
data variable is used by the library, I don't know what it should contain but debuggin i've found that when the script crashes it has this content:
<br />
<b>Warning</b>: strpos() [<a href='function.strpos'>function.strpos</a>]: Empty delimiter in <b>/PATH/wp-includes/class-wp-xmlrpc-server.php</b> on line <b>3954</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /PATH/wp-includes/class-wp-xmlrpc-server.php:3954) in <b>/PATH/wp-includes/class-IXR.php</b> on line <b>471</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /PATH/wp-includes/class-wp-xmlrpc-server.php:3954) in <b>/PATH/wp-includes/class-IXR.php</b> on line <b>472</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /PATH/wp-includes/class-wp-xmlrpc-server.php:3954) in <b>/ANOTHER_PATH/public_ht
As I said i don't know what should 'data' contain, when the code worked I never checked what it's content was.
Related
I created an e-commerce site with django. I would like to integrate a cxml punchout to link the ecommerce site and the systems of my buyers,
I would like to know here how to configure the cXML file below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.028/cXML.dtd">
<cXML payloadID="?" timestamp="?" xml:lang="en-US">
<Header>
<From>
<Credential domain="?">
<Identity>?</Identity>
</Credential>
</From>
<To>
<Credential domain="?">
<Identity>?</Identity>
</Credential>
</To>
<Sender>
<Credential domain="?">
<Identity>?</Identity>
<CredentialMac type="FromSenderCredentials" algorithm="HMAC-SHA1-96" creationDate="?"
expirationDate="?">?</CredentialMac>
</Credential>
<UserAgent>Test</UserAgent>
</Sender>
</Header>
<Request deploymentMode="test">
<PunchOutSetupRequest operation="create">
<BuyerCookie>1234ABCD</BuyerCookie>
<Extrinsic name="User">which user</Extrinsic>
<BrowserFormPost><URL>https://example.com/?BrowserFormPost</URL></BrowserFormPost>
<Contact>
<Name xml:lang="en-US">myname</Name>
<Email>whichmail#email</Email>
</Contact>
<SupplierSetup><URL>https://example.com/?SupplierSetup</URL></SupplierSetup>
</PunchOutSetupRequest>
For other information how to inform them ???
to adapt it to my project
You can find the cXML user guide in the link below, if you want to set up your own service.
https://xml.cxml.org/current/cXMLUsersGuide.pdf
Alternatively you can employ an existing punchout service like Tradecentric (~$300 a month), Greenwing (~$160 a month) or InstaPunchout (~$30 a month).
Good luck!
I have a big XML file with several article nodes. I have included only one with the problem. I try to parse it in Python to filter some data and I get the error
File "<string>", line unknown
ParseError: undefined entity Ö: line 90, column 17
Sample of the XML file
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE dblp SYSTEM "dblp.dtd">
<dblp>
<article mdate="2019-10-25" key="tr/gte/TR-0146-06-91-165" publtype="informal">
<author>Alejandro P. Buchmann</author>
<author>M. Tamer Özsu</author>
<author>Dimitrios Georgakopoulos</author>
<title>Towards a Transaction Management System for DOM.</title>
<journal>GTE Laboratories Incorporated</journal>
<volume>TR-0146-06-91-165</volume>
<month>June</month>
<year>1991</year>
<url>db/journals/gtelab/index.html#TR-0146-06-91-165</url>
</article>
</dblp>
From my search in Google, I found that this kind of error appears if you have issues in the node names. However, the line with the error is the second author, in the text.
This is my Python code
with open('xaa.xml', 'r') as xml_file:
xml_tree = etree.parse(xml_file)
The declaration of the Ouml entity is presumably in the DTD (dblp.dtd), but ElementTree does not support external DTDs. ElementTree only recognizes entities declared directly in the XML file (in the "internal subset"). This is a working example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE dblp [
<!ENTITY Ouml 'Ö'>
]>
<dblp>
<article mdate="2019-10-25" key="tr/gte/TR-0146-06-91-165" publtype="informal">
<author>Alejandro P. Buchmann</author>
<author>M. Tamer Özsu</author>
<author>Dimitrios Georgakopoulos</author>
<title>Towards a Transaction Management System for DOM.</title>
<journal>GTE Laboratories Incorporated</journal>
<volume>TR-0146-06-91-165</volume>
<month>June</month>
<year>1991</year>
<url>db/journals/gtelab/index.html#TR-0146-06-91-165</url>
</article>
</dblp>
To parse the XML file in the question without errors, you need a more powerful XML library that supports external DTDs. lxml is a good choice for that.
the following code gives me the python error 'failed to parse' addon.xml:
(I've used an online checker and it says "error on line 33 at column 15: Opening and ending tag mismatch: description line 0 and extension" - which is the very end of the /extension end tag at the end of the document).
Any advice would be appreciated. This worked yesterday and I have no idea why it's not working at all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.audio.criminalpodcast" name="Criminal Podcast" version="1.1.0" provider-name="leopheard">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.xbmcswift2" version="2.4.0"/>
<import addon="script.module.beautifulsoup4" version="4.3.1"/>
<import addon="script.module.requests" version="1.1.0"/>
<import addon="script.module.routing" version="0.2.0"/> </requires>
<provides>audio</provides> </extension>
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<language></language>
<summary lang="en"></summary>
<description lang="en">description </description>
<license>The MIT License (MIT)</license>
<forum>https://forum.kodi.tv/showthread.php?tid=344790</forum>
<email>leopheard#gmail.com</email>
<source>https://github.com/leopheard/criminalpodcast</source>
<website>http://www.thisiscriminal.com</website>
<audio_guide></audio_guide>
<assets>
<icon>icon.png</icon>
<fanart>fanart.jpg</fanart>
<screenshot>resources/media/Criminal_SocialShare_2.png</screenshot>
<screenshot>resources/media/Criminal_SocialShare_3.png</screenshot>
<screenshot>resources/media/Radiotopia-logo.png</screenshot>
</assets>
Your "XML" file is not well-formed, so it cannot be parsed. Find out how it was created, correct the process so the problem does not occur again, and then regenerate the file.
Files that are vaguely XML-like but not well-formed are pretty well useless. Repair is sometimes possible if the errors are very systematic, but that doesn't appear to the the case here.
Most of the time a "failed to parse" error msg is due to the XML File itself.
Check you're XML File for the correct formatting.
I once forgot the root tag and had the same error message.
i want to add entire tag to xml, below is my XML format.
<?xml version="1.0" encoding="UTF-8"?>
<ca st="true" name="XMLConfig">
<app>
<!--- I want to add entire commneted tag to XML . !
<ar ty="co" name="st">
<ly ty="pt">
<pt>value</pt>
</Layout>
</ar> -->
<roll name="roll" fN="file.log" fP="logs.gz">
<ly type="ptl">
<pt>value</pt>
</ly>
<po>
<!-- Comment /> -->
<si size="100 MB" />
<!-- Comment /> -->
</po>
<de fI="max" max="10"/>
</roll>
</app>
as shown in above file i want to add this tag in file
<ar ty="co" name="st">
<ly ty="pt">
<pt>value</pt>
</Layout>
</ar>
this is where i reached so far..
for appenders in tree.xpath('//Appenders'):
if appenders.getchildren():
appenders.remove(appenders.getchildren()[0])
appenders.insert(0, appenders.getparent().append(etree.fromstring('<ar ty="co" name="st"> <ly ty="pt"><pt>value</pt></Layout></ar>')))
this is removing all other content after new content.
any help will be appreciated.!
In my opinion the first way you did it is way better. You just made some mistakes in your insert line, it should be this:
appenders.insert(0, etree.fromstring('<ar ty="co" name="st"> <ly ty="pt"><pt>value</pt></ly></ar>')))
I'm surprised it didn't throw an error for you because your insert line is basically this:
appenders.insert(0,None)
Also I noticed you do something in all of your questions:
You leave out some line(s) of your xml file. (I mean why?)
You shorten the tag names in your xml but you keep their long version in the code, which is kind of annoying because the person who wants to answer you have to change the code again to see if it is working.
I got it working, !
for apps in tree.xpath('//app'):
if appenders.tag == 'app':
appenders.insert(0, etree.SubElement(appenders, 'ar', ty="Co", name="st"))
for appender in tree.xpath('//ar'):
appender.insert(0, etree.SubElement(appender, 'ly', ty="pt"))
for layout in tree.xpath('//ly'):
layout.insert(0, etree.SubElement(layout, 'pt'))
for pattern in tree.xpath('//pt'):
pattern.text = 'value'
tree.write(r'C:\value.xml', xml_declaration=True, encoding='UTF-8')
if anyone has better way to do this .. please let me know to so i can improve on this .!
I am trying to parse a XML using python ,xml example snippet:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<raml xmlns="raml21.xsd" version="2.1">
<series xmlns="" scope="USA" name="Arizona">
<header>
<log action="created"/>
</header>
<x_ns color="Blue">
<p name="timeZone">(GMT-10)</p>
</x_ns>
<x_ns color="Red">
<p name="AvgHeight">175</p>
</x_ns>
<x_ns color="black">
<p name="AvgWeight">235</p>
</x_ns>
the problem is namespaces keeps changing so as an alternative I tried to read the xmlns string first then create a dicionary using namespaces using the below code
root = raw_xml.getroot()
namespace_temp1=root.tag.split("}")
namespace_temp2=namespace_temp1[0].strip('{')
namespaces_auto={}
tag_name =["x","y","z","w","v"]
ns_name=[namespace_temp2,namespace_temp2,namespace_temp2,namespace_temp2,namespace_temp2]
namespace_temp3=zip(tag_name,ns_name)
for tag,ns in namespace_temp3:
namespaces_auto[tag]=ns
namespaces=namespaces_auto
to access a particular tag with namespace I am using the code as follows
for data in raw_xml.findall('x:x_ns',namespaces)
this pretty much solves the problem but gets stuck when the child node has blank xmlns as seen in the series tag (xmlns=""). Not Sure how to incorporate it in the code to check this condition.