The Accidental Rubyist

invalid byte sequence in UTF-8

feedvalidator and drupal xmlrpc

leave a comment »

I had hoped to validate feeds for being proper XHTML before pushing them to Google’s Blogger.
Tried feedvalidator on the XML feeds and entries returned by Google’s Blogger. Feedvalidator throws up errors on all Blogger’s XML feeds ! So that’s out.

Spent some hours trying to push an XMLRPC request to Drupal. I tried various of the MetaWeblog/MT commands but my ruby program (1.8.5 as per Hivelogic) kept throwing up the same error:
usr/local/lib/ruby/site_ruby/1.8/xmlrpc/client.rb:509:
in `do_rpc’: Wrong content-type (RuntimeError)
from /usr/local/lib/ruby/site_ruby/1.8/xmlrpc/client.rb:382:in `call2′
from /usr/local/lib/ruby/site_ruby/1.8/xmlrpc/client.rb:372:in `call’

Surprisingly, ecto and mtsend.py are connecting and posting fine from here. Could not figure out from mtsend.py’s code as to how it actually makes the call.

My code was as follows:
server = XMLRPC::Client.new( “kalki.benegal.org”, “/xmlrpc.php”)
# # Call the remote server and get our result
result = server.call(“mt.supportedMethods”);
#result = server.call(“mt.supportedTextFilters”);
#result = server.call(“metaWeblog.getRecentPosts”, mymap);
#result = server.call(“mt.supportedTextFilters”, mymap)

OK ! Found out more.
I opened client.rb and found that this exception is raised if the return type is “text/html”.
I printed the data returned by the server and found that all the supported methods WERE coming through fine.
The document returned by drupal seems to be xml with an xml header, but the content type was “text/html;charset=utf-8”.
So i suppressed the “raise” in the following block:



if resp[“Content-Type”] != “text/xml”
if resp[“Content-Type”] == “text/html”
raise “Wrong content-type: \n#{data}”
else
raise “Wrong content-type”
end
end


Now the process didn’t complete and had to be aborted.

I checked the output returned by LiveJournal on this page:http://www.sixapart.com/developers/xmlrpc/blogger_api/bloggergetrecentposts.html and it is the exact same format that drupal is returning in.
AND SOOO … i hardcoded the content type of the return value to xml, by adding a line:
resp[“Content-Type”] = “text/xml”
and VOILA! it works!!!
This means that if the returned content type were to even have been:
“text/xml;charset=utf-8” the problem would still have occured since client.rb checks for exactly “text/xml

Advertisements

Written by totalrecall

March 18, 2007 at 12:06 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: