TweepError:期望的长度,发现了意外的值pandas jupyter笔记本 [英] TweepError: Expecting length, unexpected value found pandas jupyter notebook

查看:123
本文介绍了TweepError:期望的长度,发现了意外的值pandas jupyter笔记本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,试图初始化一个类的实例,但出现了Tweep错误

This is my code, trying to initialize an instance of a class and I am getting a Tweep Error

query = 'vacation'
max_tweets = 1000

myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener = myStreamListener)
myStream.filter(track=[query])

返回的错误如下:

TweepError                                Traceback (most recent call last)
<ipython-input-31-227d7853c42e> in <module>()
      4 myStreamListener = MyStreamListener()
      5 myStream = tweepy.Stream(auth = api.auth, listener = myStreamListener)
----> 6 myStream.filter(track=[query])

C:\Program Files\Anaconda3\lib\site-packages\tweepy-3.6.0-py3.5.egg\tweepy\streaming.py in filter(self, follow, track, async, locations, stall_warnings, languages, encoding, filter_level)
    448         self.session.params = {'delimited': 'length'}
    449         self.host = 'stream.twitter.com'
--> 450         self._start(async)
    451 
    452     def sitestream(self, follow, stall_warnings=False,

C:\Program Files\Anaconda3\lib\site-packages\tweepy-3.6.0-py3.5.egg\tweepy\streaming.py in _start(self, async)
    362             self._thread.start()
    363         else:
--> 364             self._run()
    365 
    366     def on_closed(self, resp):

C:\Program Files\Anaconda3\lib\site-packages\tweepy-3.6.0-py3.5.egg\tweepy\streaming.py in _run(self)
    295             # call a handler first so that the exception can be logged.
    296             self.listener.on_exception(exc_info[1])
--> 297             six.reraise(*exc_info)
    298 
    299     def _data(self, data):

C:\Program Files\Anaconda3\lib\site-packages\six.py in reraise(tp, value, tb)
    684         if value.__traceback__ is not tb:
    685             raise value.with_traceback(tb)
--> 686         raise value
    687 
    688 else:

C:\Program Files\Anaconda3\lib\site-packages\tweepy-3.6.0-py3.5.egg\tweepy\streaming.py in _run(self)
    264                     self.snooze_time = self.snooze_time_step
    265                     self.listener.on_connect()
--> 266                     self._read_loop(resp)
    267             except (Timeout, ssl.SSLError) as exc:
    268                 # This is still necessary, as a SSLError can actually be

C:\Program Files\Anaconda3\lib\site-packages\tweepy-3.6.0-py3.5.egg\tweepy\streaming.py in _read_loop(self, resp)
    321                     break
    322                 else:
--> 323                     raise TweepError('Expecting length, unexpected value found')
    324 
    325             next_status_obj = buf.read_len(length)

TweepError: Expecting length, unexpected value found

我尝试对此进行一些研究,但是我运气不佳,非常感谢您的帮助!谢谢!

I tried to do some research on this, but I ran out of luck, and help is very much appreciated! thank you!

推荐答案

我正在使用tweepy库的克隆版本(因为开发团队尚未将最新版本推送到pip,而以前的版本现在会引发Nonetype错误,并且然后).我多次遇到相同的错误.错误是通过以下方法进行的:

I am working with the cloned version of tweepy library (as the dev team have not pushed the latest release to pip and the previous version throws a Nonetype error now and then). I ran into the same error a number of times. The error is in the following method:

def _read_loop(self, resp):
    charset = resp.headers.get('content-type', default='')
    enc_search = re.search('charset=(?P<enc>\S*)', charset)
    if enc_search is not None:
        encoding = enc_search.group('enc')
    else:
        encoding = 'utf-8'

    buf = ReadBuffer(resp.raw, self.chunk_size, encoding=encoding)

    while self.running and not resp.raw.closed:
        length = 0
        while not resp.raw.closed:
            line = buf.read_line()
            if not line:
                self.listener.keep_alive()  # keep-alive new lines are expected
            elif line.strip().isdigit():
                length = int(line)
                break
            else:
                raise TweepError('Expecting length, unexpected value found')

        next_status_obj = buf.read_len(length)
        if self.running and next_status_obj:


self._data(next_status_obj)

我已将

raise TweepError('Expecting length, unexpected value found')

替换为

self.listener.keep_alive()

,到目前为止,一切正常,但最终开发人员团队需要解决此问题.

And so far it is working ok but ultimately the tweepy dev team needs to address this.

这篇关于TweepError:期望的长度,发现了意外的值pandas jupyter笔记本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆