0
嘿我在Neo4j的在python使用py2neo包中創建一組節點中的Neo4j節點。類似的一段代碼適用於另一組節點,但在這種情況下不起作用。只有UnicodeDecodeError錯誤而創建使用Python(py2neo)
from py2neo import *
rf = open('dataset.txt','r')
sf = rf.read().split('\n')
rf.close()
L = []
for i in range(len(sf)):
X = sf[i].split('\t')
L.append(X)
for i in range(len(L)):
L[i][0] = int(L[i][0])
L[i][1] = int(L[i][1])
L[i][4] = int(L[i][4])
L[i][5] = float(L[i][5])
L[i][6] = float(L[i][6])
L[i][8] = float(L[i][8])
L[i][9] = float(L[i][9])
L[i][10] = float(L[i][10])
L[i][19] = float(L[i][19])
def conGraph():
authenticate("localhost:7474","neo4j","neo")
graph = Graph("http://localhost:7474/db/data/")
return graph
def createProducts():
graph = conGraph()
L1, L2, L3, L4, L5, L6 = [], [], [], [], [], []
for i in range(len(L)):
if L[i][17] not in L1:
L1.append(L[i][17])
L2.append(L[i][15])
L3.append(L[i][16])
L4.append(L[i][18])
L5.append(float(L[i][9]))
L6.append(float(L[i][19]))
for i in range(len(L1)):
p = Node("Product", name = L1[i], category = L2[i], subcategory = L3[i], container = L4[i], unitprice = L5[i], basemargin = L6[i])
graph.create(p)
createProducts()
第一點被創建,然後發生瞭如下錯誤:
Traceback (most recent call last):
File "C:\Documents and Settings\Administrator\Desktop\AstroMite\lambda\test.py", line 44, in <module>
createProducts()
File "C:\Documents and Settings\Administrator\Desktop\AstroMite\lambda\test.py", line 41, in createProducts
p = Node("Product", name = L1[i], category = L2[i], subcategory = L3[i], container = L4[i], unitprice = L5[i], basemargin = L6[i])
File "C:\Python27\lib\site-packages\py2neo\core.py", line 1458, in __init__
PropertyContainer.__init__(self, **properties)
File "C:\Python27\lib\site-packages\py2neo\core.py", line 1223, in __init__
self.__properties = PropertySet(properties)
File "C:\Python27\lib\site-packages\py2neo\core.py", line 1110, in __init__
self.update(iterable, **kwargs)
File "C:\Python27\lib\site-packages\py2neo\core.py", line 1168, in update
self[key] = value
File "C:\Python27\lib\site-packages\py2neo\core.py", line 1139, in __setitem__
dict.__setitem__(self, key, cast_property(value))
File "C:\Python27\lib\site-packages\py2neo\types.py", line 55, in cast_property
value = ustr(value)
File "C:\Python27\lib\site-packages\py2neo\util.py", line 210, in ustr
return s.decode(encoding)
File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xae in position 8: invalid start byte
我搜索了相關的問題,但沒有發現任何具體的答案。
非常感謝你 – MityManiac