【问题标题】:Error, too many values to unpack错误,太多值无法解压
【发布时间】:2014-03-09 23:50:31
【问题描述】:

我需要更正此异常:“太多值无法解包”

这是我的源代码:如果我的数据库中不存在节点,或者如果它存在,我需要插入一个节点,我只添加与新节点的新关系:)

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
import tweepy
import codecs
import json
from time import clock
from py2neo import neo4j
from py2neo import node,rel

cle = 'NorVSuR1eh0xdzkex4Y4mA'
clesecrete = 'F0AbGFdmMrwNhDKYGKzEQrqXTMEViKW'
jeton = '2234554214-sBqwoOCCEBVRktuCBeVdVhu6dluUfLSbecq'
jetonsecret = 'KaagCeViNedcHrSctsGoXNHq0nWTV6E4t6x4ddXrYzL'
graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")

class listener(StreamListener):
     def on_data(self,data):

       try:
           if 'text' in data:

                tweet = json.loads(data)

                if tweet['in_reply_to_screen_name'] != None:
                    user_scr_Com=tweet['user']['screen_name']
                    print user_scr_Com
                    nod = list(graph_db.find("user_qui_a_commenter", "screen_name" , user_scr_Com ))
                    print nod

                         if len(nod)>0 :
                          for nd in nod:
#**#-My problem is here: I have a except Error, too many values to unpack**

                              User_Publication,text= graph_db.create(    
                                  node(Screen_name_User_Publication=tweet['in_reply_to_screen_name']),
                                  node(Commentaire=tweet['text'],Id_text=tweet['id_str'],source=tweet['source']),
                                  rel(nd, "user_a_commenter", 1),
                                  rel(1, "pour", 0))

                              User_Publication.add_label("user_status")
                              text.add_label("Commentaire")

                          else :
                         user_qui_a_commenter,User_Publication,text= graph_db.create(
                           node(Screen_name=tweet['user']['screen_name'],name=tweet['user']['name'],Id=tweet['user']['id_str'],Description=tweet['user']['description'],followers_count=tweet['user']['followers_count'],friends_count=tweet['user']['friends_count'],favourites_count=tweet['user']['favourites_count'],created_at=tweet['user']['created_at'],langue=tweet['user']['lang'],location=tweet['user']['location']),
                           node(Screen_name_User_Publication=tweet['in_reply_to_screen_name']),
                           node(Commentaire=tweet['text'],Id_text=tweet['id_str'],source=tweet['source']),
                           rel(0, "A_commenter_Pour", 1),
                           rel(0, "user_a_commenter", 2))
                         user_qui_a_commenter.add_label("user_qui_a_commenter")
                         User_Publication.add_label("user_status")
                         text.add_label("Commentaire")

谢谢你,我需要你的帮助

【问题讨论】:

    标签: python neo4j py2neo


    【解决方案1】:

    错误与此行相关

    User_Publication,text= graph_db.create(...

    您期望从结果中得到一个二元组,但您得到的还不止这些。

    我对 Neo4j 一无所知,但from here 似乎你得到的项目数量与你放入的数量相同。如果是这样,那么你应该期待一个四元素元组。

    # create two nodes with a connecting relationship
    alice, bob, rel = graph_db.create(
        {"name": "Alice"}, {"name": "Bob"},
        (0, "KNOWS", 1, {"since": 2006})
    )
    

    所以这会解决你的问题

    User_Publication, text, var3, var4 = graph_db.create(...

    看起来这种情况稍后会在您的代码中再次发生。将为关系和节点返回项目。

    【讨论】:

    • 我仍然有同样的例外: User_Pub,txt,a1,a2= graph_db.create( node(Screen_name_User_Publication=tweet['in_reply_to_screen_name']), node(Commentaire=tweet['text'] ), rel(nd, "user_a_commenternn", 1), rel(nd, "pour", 0)) User_Publication.add_label("user_status") text.add_label("texte_tw")
    • 您需要更新您的问题。就目前而言,我认为您发布的代码不会引发您建议的错误。我会尝试先让一个简化版本工作。那么你可能会更好地理解这个问题。
    猜你喜欢
    • 2013-05-24
    • 2020-01-20
    • 2018-12-19
    • 2015-12-20
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多