I am working on a script that uses the python services to create nodes from html files. I have made various versions of this with success over the past year but with the latest script I am working on, I am hitting something new....

all of the < and > as well as & tags are removed from the HTML on save. I am not sure if this is even a services issue but just figured I would start here to see if this has been an issue in services. I have played with input formats but that didn't *seem* to help.

I have paired down my example to something that still has the issue. I figure I am missing something.

#! /usr/bin/python


import xmlrpclib, time
import urllib


#doc_client_api|doc_widget|doc_tactic_core
node_type = "doc"
url = "<mysite>/services/xmlrpc"
uname = "siteadmin"
passwd = "<admin password>"

server = xmlrpclib.ServerProxy(url)

anon_session = server.system.connect()
anon_session_id = anon_session['sessid']

auth_session = server.user.login(anon_session_id, uname, passwd)
auth_session_id = auth_session['sessid']

print "Anon: %s" %anon_session_id
print "Auth: %s" %auth_session_id


def main():
    try:
        
 
        #pull out the body tag
        title = "test"
        body = "<html><div>TEST</div></html>"

        node = {\
            'title': title,\
	    'body': body,\
            'type': node_type,\
	    'uid': 1,\
	    'name': uname,\
	    'promote': False,\
    	    'language': 'en'\
	}

        new_node = server.node.save(auth_session_id, node)

        print "Created [%s]" %title

    except xmlrpclib.Fault, err:
        print "A fault occurred"
        print "Fault code: %d" % err.faultCode
        print "Fault string: %s" % err.faultString
        raise

if __name__ == '__main__':
    main() 

The resulting body looks like

htmldivTEST/div/html 

Thanks in advance for any pointers

cheers
-Dan Kitchen

Comments

btully’s picture

Priority: Normal » Major

We're having the same exact issue when trying to deploy nodes from one site to another using Deploy and Services. The node body deployed to the remote server has all "<", ">" and "&" characters removed, which causes all sorts of weird formatting issues since all HTML tags get broken.

Any ideas?

marcingy’s picture

Priority: Major » Normal

Support requests are by there nature normal. If the characters are in the database then you are seeing the effect of drupals input filter (which filters on output). If the data doesn't reach the database then the issue is likely with your client stripping on send.

btully’s picture

Sorry about that, Marc! We're using Deploy module to send node contents from our staging server to production server. All within Drupal. It's been working fine for us for months. But recently when the node gets deployed to production, the version on production has all the <, > and & characters stripped from the $node->body content, within the database. The original source on staging server is complete/correct, even when we edit the node and save it. But somehow when the same node gets sent remotely via Services the content gets corrupted. When you refer to "your client stripping on send", which client are you referring to?

Many thanks,
Brian

marcingy’s picture

No problem. So you are using the standard drupal xmlrpc client then by bad I misread. I'll ping hejrocker and see if has any ideas as he knows both deploy and services.

btully’s picture

Thanks, Marc. Yes, all standard drupal xmlrpc. We're still trying to debug this to no avail. The only thing I could find in the whole site code that explicitly acts on <, >, and & is drupal_to_js() which replaces the chars with their unicode equivalent. But not sure how that would be getting invoked to process the node body content.

marcingy’s picture

Status: Active » Closed (won't fix)

Closing at 6.x.2 is no longer supported