Dan R. Olsen III
python at dan-olsen.net
Wed Dec 22 15:15:53 EST 2004
I am trying to parse a file that I am getting from a url. However, I keep getting an error saying that a module does not have an attribute parse. Here is the code followed by the error: ----- BEGIN CODE ----- import xml.dom.minidom #from xml.dom import minidom from mod_python import apache from dbxml import * import urllib ### GET ALL THE URLS FROM THE OPML FILE ####################################### def get_urls(req, url): #req.write(url + "\n") xmlfile = urllib.urlopen('http://www.windley.com/gems/mySubscriptions.opml') #req.write(xmlfile + "Great!!") filedoc = xml.dom.minidom.parse(xmlfile) req.write("HOW ABOUT HERE\n") feeds = [] text = filedoc.getElementsByTagName("outline") for nodes in text: for (name, value) in nodes.attributes.items(): if name == 'xmlUrl': feeds.append(value) return feeds ### SPLIT THE ARGUMENTS PASSED TO THE URL ######################################### def split_args(args): rose_args = {} if args == None: return rose_args arglist = args.split('&') for arg in arglist: tmp = arg.split('=') if len(tmp) == 1: rose_args[tmp[0]] = None else: rose_args[tmp[0].upper()] = tmp[1] return rose_args ### SEND ERROR IF SOMETHING GOES WRONG ###################################### def send_html_error(req, s, status): req.content_type = 'text/html' req.send_http_header() req.write('<p>' + s + '</p>') raise apache.SERVER_RETURN, status ### MAIN HANDLER METHOD WHERE ARE THE MAIN CALLS ARE MADE ######################################################### def handler(req): req.send_http_header() request = req.args rose_args = split_args(req.args) if len(rose_args) == 0: send_html_error(req, 'No parameters found', apache.HTTP_BAD_REQUEST) if len(rose_args) != 2: send_html_error(req, '<strong><font color=\"RED\">You must have two parameters, one for \nyour OPML file and one for the FLAVOR</font></strong>', apache.HTTP_PRECONDITION_FAILED) url = rose_args.get('URL', None) flavor = rose_args.get('FLAVOR', None) if url == None: send_html_error(req, '<strong><font color=\"RED\">No URL parameter found</font></strong>', apache.HTTP_PRECONDITION_FAILED) else: req.write("OPML: " + url + "\n") if flavor == None: send_html_error(req, '<strong><font color=\"RED\">No FLAVOR parameter found</font></strong>', apache.HTTP_PRECONDITION_FAILED) else: flavor = flavor.upper() if(flavor != 'RSS' and flavor != 'ATOM'): req.write("FLAVOR: " + flavor + "\n") send_html_error(req, '<strong><font color=\"RED\">The FLAVOR you entered is not a valid flavor</font></strong>', apache.HTTP_PRECONDITION_FAILED) else: req.write("FLAVOR: " + flavor + "\n") rose_urls = get_urls(req, url) req.write(rose_urls[0]) mgr = XmlManager() container = mgr.openContainer("/web/htdocs/dev/danolsencreatedme.dbxml") return apache.OK ----- END CODE ----- ----- BEGIN OUTPUT ------ OPML: http://www.windley.com/gems/mySubscriptions.opml FLAVOR: RSS Mod_python error: "PythonHandler rose" Traceback (most recent call last): File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 193, in Dispatch result = object(req) File "/web/htdocs/dev/rose.py", line 78, in handler rose_urls = get_urls(req, url) File "/web/htdocs/dev/rose.py", line 14, in get_urls filedoc = xml.dom.minidom.parse(xmlfile) File "/usr/lib/python2.3/site-packages/_xmlplus/dom/minidom.py", line 1908, in parse return expatbuilder.parse(file) AttributeError: 'module' object has no attribute 'parse' ----- END OUTPUT ----- If anyone can clue me in on why this is happening that would be great! Dan Olsen
|