Pregunta

I need to correct this Exception please : "too many values to unpack"

This is my source code: I need to insert a node if not exist in my DB or if it exists I add just new relationship with new nodes :)

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")

Thank you please i need your help

¿Fue útil?

Solución

The error is associated with this line

User_Publication,text= graph_db.create(...

you are expecting a two-tuple from the result but you are getting more than that.

I don't know anything about Neo4j but from here it seems you get out the same number of items you put in. If so then you should expect a four-element tuple.

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

So this would fix your problem

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

It looks like this will happen again later in your code. Items will be returned for the relationships as well as for the nodes.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top