Skip to main content.
September 14th, 2007

Python’s SimpleXMLRPCServer - How to Serve from a Different Machine

It turns out that following the example from Python’s SimpleXMLRPCServer documentation of serving from localhost only works for well, localhost:

from SimpleXMLRPCServer import SimpleXMLRPCServer
# Create server
server = SimpleXMLRPCServer(("localhost", 8000))
#snip ...(register functions here, see example)
server.register_instance(MyFuncs())
# Run the server's main loop
server.serve_forever()

To make your server available to other computers on your network you should do something like this:

import socket
from SimpleXMLRPCServer import SimpleXMLRPCServer
# Create server
server = SimpleXMLRPCServer((socket.gethostbyname(socket.gethostname()), 8000))
#snip ...(register functions here, see example)
server.register_instance(MyFuncs())
server.serve_forever()

Open question, will this work for serving to the internet at large, or do I need to do something differently? I’m actually not sure why localhost doesn’t work across the LAN. Does anyone know?

I found this answer by a google code search for SimpleXMLRPCServer.

Posted by Greg Pinero (Primary Searcher) as Python, Web Services at 11:46 AM MST

3 Comments »

January 30th, 2007

Best Javascript IRC Chat Room

Here’s the biggest one, the folks seem helpful:
Javascript IRC Chat on Freenode


Or you can find a lot more options with this search.

Posted by Greg Pinero (Primary Searcher) as Other, Web Services, Searching Better at 2:35 PM MST

Comments Off

January 14th, 2007

Google Reader doesn’t Refresh When You Tell it to

I’ve been noticing for a while that Google Reader is very delayed in showing me updates to feeds. I always figured it was my fault somehow, perhaps the specific feeds I was subscribed to?

But this thread and many others like it has everyone complaining of this problem. The best I can discern is that Google Readers refreshes feeds only on its own schedule (possibly as little as once every three hours!) and hitting the refresh button above the feed does nothing.

It was pointed out that this could be a bandwidth issue as in a lot of webmasters would get unhappy if (millions?) of Google Reader users were always hitting refresh and actually having Google re-access the feed. But I don’t want to hear excuses, I want an RSS reader that works! Timely updates are the killer app of RSS readers, get it fixed!

Can anyone reccomend a better web based RSS reader?

Tags: , , , , ,

Posted by Greg Pinero (Primary Searcher) as Other, Web Services at 3:21 PM MST

4 Comments »

December 13th, 2006

FTP Ignorance

I spent over an hour trying to run the sample code below. This comes from the sample code from ftputil (The best FTP library for Python by the way.)

# download some files from the login directory
import ftputil
host = ftputil.FTPHost('ftp://ftp.kernel.org/')
names = host.listdir(host.curdir)
for name in names:
    if host.path.isfile(name):
        host.download(name, name, 'b')        # remote, local, binary mode

And I just kept getting this error!

raise FTPOSError(ftp_error)
FTPOSError: (11001, 'getaddrinfo failed')
Debugging info: ftputil 2.1.1, Python 2.4.2 (win32)

Anyway the simple mistake ended up being that I needed to use ftp.kernel.org/ and not ftp://ftp.kernel.org/. So that’s the answer if you’re ever stuck, omit the ftp:// prefix.

Posted by Greg Pinero (Primary Searcher) as Python, Web Services at 6:03 PM MST

2 Comments »

September 30th, 2006

Super Easy XML Parsing in Python

Getting information I need out of XML is one of those tasks that occurs rarely enough that I never get to develop that profound understanding of XML documents and their parsing that we all so desire. It also means that every time I want to work with a piece of XML I have to re-learn the bare minimum of Python XML processing.

To fix this problem I am posting the snippet of bare-minimum, cheap XML processing code I usually come up with, using my latest XML processing problem as an illustration.

Be sure to advise me if I’m doing something dreadfully wrong, or if you’ve come up with a superior code snippet for processing XML that involves less cruft. Also stay tuned to my announcements page to see how this code is going to contribute to automatically adding birthdays to Google Calendar!

And finally here is how I get XML into a list of dictionaries where each dictionary contains the important values of the calendar entry elements for a piece of XML like this:

<entry>
		<id>
			http://www.google.com/calendar/feeds/default/private/full/...
		</id>
		<published>
			2006-09-15T04:55:44.000Z
		</published>
		<updated>
			2006-09-15T04:55:44.000Z
		</updated>
		<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
		<title type="text">
			Mom's Birthday
		</title>
		<content type="text"/>
		<link href="http://www.google.com/calendar/event?eid=..." rel="alternate" title="alternate" type="text/html"/>
		<link href="http://www.google.com/calendar/feeds/default/private/full/..." rel="self" type="application/atom+xml"/>
		<link href="http://www.google.com/calendar/feeds/default/private/full/..." rel="edit" type="application/atom+xml"/>
		<author>
			<name>
				....
			</name>
			<email>
				....
			</email>
		</author>
		<gd:comments>
			<gd:feedLink href="http://www.google.com/..."/>
		</gd:comments>
		<gd:visibility value="http://schemas.google.com/g/2005#event.default"/>
		<gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
		<gd:transparency value="http://schemas.google.com/g/2005#event.opaque"/>
		<gCal:sendEventNotifications value="true"/>
		<gd:where valueString=""/>
		<gd:when endTime="2006-09-21" startTime="2006-09-20">
			<gd:reminder minutes="2880"/>
		</gd:when>
	</entry>

Here is the code. I just feed this function the raw xml returned by Google calendar and it gives me a list of dictionaries where each dictionary holds information from that event like title, and startdate. It’s not that complicated but I always get hung up on all that firstChild and data stuff so it’s easier for me to just copy this snippet and modify it for whatever XML I’m dealing with than redoing it each time.

def parse_entries(raw_xml):
    dom = xml.dom.minidom.parseString(data) #Make the dom from raw xml
    entries=dom.getElementsByTagName('entry') #Pull out all entry's
    result_entries=[] #Make an empty container to fill up and return
    for entry in entries:
        dentry={} #Make empty dict to hold info on an entry
        #Fill up the dict
        dentry['id']=entry.getElementsByTagName('id')[0].firstChild.data
        dentry['published']=entry.getElementsByTagName('published')[0].firstChild.data
        dentry['updated']=entry.getElementsByTagName('updated')[0].firstChild.data
        dentry['title']=entry.getElementsByTagName('title')[0].firstChild.data
        try: dentry['content']=entry.getElementsByTagName('content')[0].firstChild.data
        except AttributeError: dentry['content']=''
        dentry['startTime']=entry.getElementsByTagName('gd:when')[0].getAttribute('startTime')
        dentry['endTime']=entry.getElementsByTagName('gd:when')[0].getAttribute('endTime')
        result_entries.append(dentry)
    return result_entries

For the future I’d like to consider trying pyRXP instead which promises to be 97% faster than minidom and parses XML directly into some kind of mix of tuples and other Python primitives.

By the way, if you’re interested in learning more about working with Google Calendar’s API, I’ll be making a few posts on Answer My Searches soon detailing how to do that. (And I may end up even releasing a library for Python). So go ahead and subscribe if you haven’t yet ;-)

Tags: , , , , , , ,

Posted by Greg Pinero (Primary Searcher) as Python, Web Services at 6:23 PM MST

2 Comments »

« Previous Entries