python序列项0:预期的str实例,找到NoneType

时间:2017-06-06 07:22:18

标签: python python-3.x converter typeerror rdflib

我正在尝试将本地.xml文件转换为.ttl并使用此代码:

import rdflib
g=rdflib.Graph()

g.parse("C:\\Users\\Username\\Desktop\\public-12T23.xml",format='xml')
print (g.serialize(format='turtle'))

我收到了这个错误

TypeError                                 Traceback (most recent call last)
<ipython-input-3-d52cc014f61e> in <module>()
      2 g=rdflib.Graph()
      3 
----> 4 g.parse("C:\\Users\\Saeid\\Desktop\\public-12T23.xml", format='xml')
      5 print (g.serialize(format='turtle'))

C:\Program Files\Anaconda3\lib\site-packages\rdflib\graph.py in parse(self, >source, publicID, format, location, file, data, **args)
   1041         parser = plugin.get(format, Parser)()
   1042         try:
-> 1043             parser.parse(source, self, **args)
   1044         finally:
   1045             if source.auto_close:

C:\Program Files\Anaconda3\lib\site-packages\rdflib\plugins\parsers\rdfxml.py >in parse(self, source, sink, **args)
    576         # content_handler.reset()
    577         # self._parser.reset()
--> 578         self._parser.parse(source)

C:\Program Files\Anaconda3\lib\xml\sax\expatreader.py in parse(self, source)
    108         self.reset()
    109         self._cont_handler.setDocumentLocator(ExpatLocator(self))
--> 110         xmlreader.IncrementalParser.parse(self, source)
    111 
    112     def prepareParser(self, source):

C:\Program Files\Anaconda3\lib\xml\sax\xmlreader.py in parse(self, source)
    123         buffer = file.read(self._bufsize)
    124         while buffer:
--> 125             self.feed(buffer)
    126             buffer = file.read(self._bufsize)
    127         self.close()

C:\Program Files\Anaconda3\lib\xml\sax\expatreader.py in feed(self, data, >isFinal)
    208             # document. When feeding chunks, they are not normally >final -
    209             # except when invoked from close.
--> 210             self._parser.Parse(data, isFinal)
    211         except expat.error as e:
    212             exc = SAXParseException(expat.ErrorString(e.code), e, self)

..\Modules\pyexpat.c in EndElement()

C:\Program Files\Anaconda3\lib\xml\sax\expatreader.py in end_element_ns(self, >name)
    368             pair = tuple(pair)
    369 
--> 370         self._cont_handler.endElementNS(pair, None)
    371 
    372     # this is not used (call directly to ContentHandler)

C:\Program Files\Anaconda3\lib\site-packages\rdflib\plugins\parsers\rdfxml.py >in endElementNS(self, name, qname)
    158 
    159     def endElementNS(self, name, qname):
--> 160         self.current.end(name, qname)
    161         self.stack.pop()
    162 

C:\Program Files\Anaconda3\lib\site-packages\rdflib\plugins\parsers\rdfxml.py >in node_element_end(self, name, qname)
    330         if self.parent.object and self.current != self.stack[2]:
    331 
--> 332             self.error("Repeat node-elements inside property elements: >%s"%"".join(name))
    333 
    334         self.parent.object = self.current.subject

TypeError: sequence item 0: expected str instance, NoneType found

我知道这并不像我想象的那么容易,但是当我使用这些脚本here时,我也遇到了同样的错误。

0 个答案:

没有答案