Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 两次偶然但持续的错误”;应为长度,找到意外值“;_Python_Twitter_Tweepy - Fatal编程技术网

Python 两次偶然但持续的错误”;应为长度,找到意外值“;

Python 两次偶然但持续的错误”;应为长度,找到意外值“;,python,twitter,tweepy,Python,Twitter,Tweepy,我使用Tweepy和Twitter流媒体API组合了一个python脚本,该脚本使用某个hashtag收集tweet,并将其保存到数据库中。我将它托管在自己的Ubuntu服务器上,我通过ssh从我的计算机登录到该服务器 我一直在通过推特自己测试代码,使用hashtag。当我启动脚本时,它将流式传输前一两条tweet,然后在下一条上,我得到以下错误: Traceback (most recent call last): File "stream.py", line 69, in <mod

我使用Tweepy和Twitter流媒体API组合了一个python脚本,该脚本使用某个hashtag收集tweet,并将其保存到数据库中。我将它托管在自己的Ubuntu服务器上,我通过ssh从我的计算机登录到该服务器

我一直在通过推特自己测试代码,使用hashtag。当我启动脚本时,它将流式传输前一两条tweet,然后在下一条上,我得到以下错误:

Traceback (most recent call last):
  File "stream.py", line 69, in <module>
    stream.filter(track=settings.TRACK_TERMS)
  File "build/bdist.linux-x86_64/egg/tweepy/streaming.py", line 450, in filter
  File "build/bdist.linux-x86_64/egg/tweepy/streaming.py", line 364, in _start
  File "build/bdist.linux-x86_64/egg/tweepy/streaming.py", line 297, in _run
  File "build/bdist.linux-x86_64/egg/tweepy/streaming.py", line 266, in _run
  File "build/bdist.linux-x86_64/egg/tweepy/streaming.py", line 323, in _read_loop
tweepy.error.TweepError: Expecting length, unexpected value found

我自己还没有使用Tweeps,但我想我应该先修改
build/bdist.linux-x86_64/egg/tweepy/streaming.py
,在第323行之前添加一些print语句,以检查预期的变量、预期的值以及实际使用的内容。。因为那里似乎不匹配。。然后,您可以返回查找故障。从3.4更新到3.5后,我有完全相同的错误。@SB87谢谢您的建议!该文件似乎对我完全隐藏,我不知道如何访问它。即使我将文件浏览器设置为“显示隐藏文件”。我可以找到一个名为streaming.py的文件,但它似乎不是我需要的文件。鸡蛋是不可接近的。我最终放弃了Tweepy,转而使用最简单的方法调用TwitterAPI并将tweets转储到json中。现在我的问题是{hangup:True}错误。我没有意识到Twitter流媒体API会如此难以使用。我自己也没有使用过Tweeps,但我想我应该先适应
build/bdist.linux-x86_64/egg/tweepy/streaming.py
,在第323行之前添加一些打印语句来检查需要哪些变量,期望什么样的值,并检查实际通过的值。。因为那里似乎不匹配。。然后,您可以返回查找故障。从3.4更新到3.5后,我有完全相同的错误。@SB87谢谢您的建议!该文件似乎对我完全隐藏,我不知道如何访问它。即使我将文件浏览器设置为“显示隐藏文件”。我可以找到一个名为streaming.py的文件,但它似乎不是我需要的文件。鸡蛋是不可接近的。我最终放弃了Tweepy,转而使用最简单的方法调用TwitterAPI并将tweets转储到json中。现在我的问题是{hangup:True}错误。没有意识到Twitter流媒体API会如此难以使用。
import settings
import dataset
import tweepy
from textblob import TextBlob
from sqlalchemy.exc import ProgrammingError
import json

db = dataset.connect(settings.CONNECTION_STRING)

class StreamListener(tweepy.StreamListener):

    def on_status(self, status):
        print(status.text)
        description = status.user.description
        text = status.text
        name = status.user.screen_name
        followers = status.user.followers_count
        created = status.created_at
        retweets = status.retweet_count
        id_str = status.id_str
        #creating and storing in database

        table = db[settings.TABLE_NAME]
        try:
            table.insert(dict(
                user_description=description,
                text=text,
                user_name=name,
                user_followers=followers,
                id_str=id_str,
                created=created,
                retweet_count=retweets,
            ))
        except ProgrammingError as err:
            print(err)

    def on_error(self, status_code):
        if status_code == 420:
            #returning False in on_data disconnects the stream
            return False

auth = tweepy.OAuthHandler(settings.TWITTER_APP_KEY, settings.TWITTER_APP_SECRET)
auth.set_access_token(settings.TWITTER_KEY, settings.TWITTER_SECRET)
api = tweepy.API(auth)

stream_listener = StreamListener()
stream = tweepy.Stream(auth=api.auth, listener=stream_listener)
stream.filter(track=settings.TRACK_TERMS)