I've written an xml parser using xml.sax which works most of the time
but often traces back when trying to read a file. The output of the
traceback is below:
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py ",
line 271, in run
main()
File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py ",
line 502, in main
body = page_handler(*a rgs, **cherrypy.requ est.paramMap)
File "netscan.py ", line 160, in index
parse()
File "netscan.py ", line 117, in parse
parser.parse ( scan_results )
File "/usr/lib/python2.4/xml/sax/expatreader.py" , line 107, in parse
xmlreader.Incre mentalParser.pa rse(self, source)
File "/usr/lib/python2.4/xml/sax/xmlreader.py", line 125, in parse
self.close()
File "/usr/lib/python2.4/xml/sax/expatreader.py" , line 217, in close
self.feed("", isFinal = 1)
File "/usr/lib/python2.4/xml/sax/expatreader.py" , line 211, in feed
self._err_handl er.fatalError(e xc)
File "/usr/lib/python2.4/xml/sax/handler.py", line 38, in fatalError
raise exception
SAXParseExcepti on: /var/log/netscan/scanresults.txt :8:0: no element found
I don't understand why it's telling me that no element is found. It
looks like a problem inside xml.sax, but I'm not sure if I've caused
it or how. The xml file is good and is generated by nmap, it's not
missing tags or anything and is quite small. My script code which has
generated this is below:
#!/usr/bin/env python
import xml.sax
import sys
import os
dir = '/var/log/netscan'
scan = 'scanresults.tx t'
temp = 'tempscan.txt'
scan_results = dir + '/' + scan
temp_results = dir + '/' + temp
if not os.path.isdir(d ir):
sys.exit("%s does not exist! exiting..." % dir)
network = [
# {
# "status" : "",
# "address" : "",
# "hostname" : "",
# "port[0]" : "",
# "protocol[0]" : "",
# "service[0]" : "",
# "state[0]" : "",
# "product[0]" : "",
# "version[0]" : "",
# "extrainfo[0]" : ""
# }
]
class scanparser( xml.sax.Content Handler ):
def __init__(self):
self.host = {}
self.host['status'] = ""
self.host['address'] = ""
self.host['hostname'] = ""
self.host['port'] = []
self.host['protocol'] = []
self.host['service'] = []
self.host['state'] = []
self.host['product'] = []
self.host['version'] = []
self.host['extrainfo'] = []
def startElement(se lf,name,attribu tes):
global scan_start,scan _stop
if name =='nmaprun':
scan_start = attributes.getV alue('startstr' )
elif name == 'finished':
scan_stop = attributes.getV alue('timestr')
elif name =='status':
self.host['status'] = attributes.getV alue('state')
elif name == 'address':
if attributes.getV alue('addrtype' ) == 'ipv4':
self.host['address'] = attributes.getV alue('addr')
elif name == 'hostname':
self.host['hostname'] = attributes.getV alue('name')
elif name == 'port':
self.host['port'].append( attributes.getV alue('portid') )
self.host['protocol'].append( attributes.getV alue('protocol' ) )
elif name == 'service':
self.host['service'].append( attributes.getV alue('name') )
if attributes.has_ key('product'):
self.host['product'].append( attributes.getV alue('product') )
else:
self.host['product'].append("")
if attributes.has_ key('version'):
self.host['version'].append( attributes.getV alue('version') )
else:
self.host['version'].append('')
if attributes.has_ key('extrainfo' ):
self.host['extrainfo'].append(
attributes.getV alue('extrainfo ') )
else:
self.host['extrainfo'].append('')
elif name == 'state':
self.host['state'].append( attributes.getV alue('state') )
def endElement(self ,name):
if name == 'host':
network.append( self.host.copy( ))
self.host = {}
self.host['status'] = ""
self.host['address'] = ""
self.host['hostname'] = ""
self.host['port'] = []
self.host['protocol'] = []
self.host['service'] = []
self.host['state'] = []
self.host['product'] = []
self.host['version'] = []
self.host['extrainfo'] = []
def parse():
global network
parser = xml.sax.make_pa rser()
parser.setConte ntHandler( scanparser() )
network = []
parser.parse ( scan_results )
parse()
(Well, really it runs from cherrypy but for brevity I've left that out)
Any help or pointers anybody could give would be greatly appreciated...
Hari 0 1313 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: s a n j a y |
last post by:
Hi All,
I am want to upgrade MySQL from 4.0 to 4.1 on linux. The reason being the
subqueries.
Problem is
Failed dependencies:
libcrypto.so.0.9.6 is needed by MySQL-Max-4.1.0-0
libssl.so.0.9.6 is needed by MySQL-Max-4.1.0-0
|
by: Steven T. Hatton |
last post by:
Some people have suggested the desire for code completion and refined
edit-time error detection are an indication of incompetence on the part of
the programmer who wants such features. Unfortunately these ad hominem
rhetorts are frequently introduced into purely technical discussions on the
feasibility of supporting such functionality in C++. That usually serves
to divert the discussion from the technical subject to a discussion of the...
|
by: kabrit |
last post by:
Entrez "aide" pour afficher à nouveau les noms de produits.
Entrez "quitter" pour quitter.
***********************************************************
DB2.PE
IBM_db2msen81...
Preparing...
##################################################
IBM_db2msen81
|
by: StBond |
last post by:
Hi everyone,
I am new to Access and Visual Basic so things my be getting across a
bit cloudy. I only started using VB for one week.
I am having a little problem with the database that I am working on. I
am working with MS Access 2002. And I am having a problem with one of
my charts.
I will explain how everything is laid out then go into details.
|
by: intrepid_dw |
last post by:
Hello, all.
I've created a C# dll that contains, among other things, two functions
dealing with byte arrays. The first is a function that returns a byte
array, and the other is intended to receive a byte array as one of its
parameters. The project is marked for COM interop, and that all
proceeds normally.
When I reference the type library in the VB6 project, and write the
code to call the function that returns the byte array, it works
| |
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c */
#include <time.h>
|
by: Nacho |
last post by:
Hello..
I have one problem with my reusable function to validate date..
I want to use this function to all my web project no validate date, but
It's works fine if I have one textbox to validate in the same form, If
I have two textbox the return doesn't works correctly.. how can I do
this?
if (document.Form1.TxtFechaIng.value!=''){
|
by: Lars Eighner |
last post by:
I take this example from a writer in alt.usage.english
<news://r3jie3p93s1eaflgcckn2hinf3li4mnfud@4ax.com>, where the question
of whether the "and" is required came up strictly as an issue of English
usage, because it illustrates a recurring problem in HTML markup.
How should this be marked up? Yes, generally, "Bob went to the store..."
is marked up in P and the items as LI in OL. But logically, the list
belongs to the paragraph. ...
|
by: C_guy |
last post by:
Does anyone know of a (hopefully free) tool that can traverse a
project and determine which "#include"s are not needed or needed in
every .C file? This would be helpful in removing header inclusions
that are redundant and/or unnecessary.
Thanks!
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |