当我试图根据特定用户的特定术语检索推文时,python抛出了一个错误

当我试图根据特定用户的特定术语检索推文时,python抛出了一个错误,python,tweepy,Python,Tweepy,pythonshell上的输出是 from __future__ import unicode_literals import tweepy consumer_key='xyz', consumer_secret='xyz', access_key='xyz', access_secret='xyz' auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access

pythonshell上的输出是

from __future__ import unicode_literals
import tweepy
consumer_key='xyz',
consumer_secret='xyz',
access_key='xyz',
access_secret='xyz'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api=tweepy.API(auth)
class CustomStreamListener(tweepy.StreamListener):
    def on_status(self, status):
        return True
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
list_users = ['17006157','59145948','157009365','16686144','68044757','33338729']   #Some ids
list_terms = ['abc','def']   #Some terms
sapi.filter(follow=list_users, track=list_terms)
回溯(最近一次呼叫最后一次):
文件“C:/Python27/nytimes/20052014/mutliple关键字from multi-user search.py”,第44行,在
过滤器(轨迹=[“列表项”])
过滤器中第313行的文件“build\bdist.win32\egg\tweepy\streaming.py”
自启动(异步)
文件“build\bdist.win32\egg\tweepy\streaming.py”,第235行,在_start中
self._run()
文件“build\bdist.win32\egg\tweepy\streaming.py”,第151行,正在运行
timeout=self.timeout,stream=True,auth=auth)
文件“C:\Python27\lib\site packages\requests-2.1.0-py2.7.egg\requests\sessions.py”,第348行,在请求中
准备=自我准备请求(req)
文件“C:\Python27\lib\site packages\requests-2.1.0-py2.7.egg\requests\sessions.py”,第286行,在prepare\u请求中
钩子=合并钩子(request.hooks,self.hooks),
文件“C:\Python27\lib\site packages\requests-2.1.0-py2.7.egg\requests\models.py”,第290行,在prepare中
self.prepare\u auth(auth,url)
文件“C:\Python27\lib\site packages\requests-2.1.0-py2.7.egg\requests\models.py”,第469行,在prepare\u auth中
r=auth(self)
文件“C:\Python27\lib\site packages\requests\u oauthlib-0.4.0-py2.7.egg\requests\u oauthlib\oauth1\u auth.py”,第63行,在调用中__
unicode(r.url)、unicode(r.method)、r.body或“”、r.headers)
文件“build\bdist.win32\egg\oauthlib\oauth1\rfc5849\\uuuu init\uuuu.py”,第280行,在符号中
request.oauth\u params.append(('oauth\u signature',self.get\u oauth\u signature(request)))
文件“build\bdist.win32\egg\oauthlib\oauth1\rfc5849\\ uuuuu init\uuuuuuu.py”,第112行,在get\u oauth\u签名中
uri,头,body=self.\u呈现(请求)
文件“build\bdist.win32\egg\oauthlib\oauth1\rfc5849\\ uuuu init\uuuu.py”,第186行,在渲染中
headers=parameters.prepare_头(request.oauth_参数,request.headers,realm=realm)
文件“build\bdist.win32\egg\oauthlib\oauth1\rfc5849\utils.py”,第32行,在包装器中
返回目标(参数、*args、**kwargs)
文件“build\bdist.win32\egg\oauthlib\oauth1\rfc5849\parameters.py”,第58行,在prepare\u标题中
转义值=utils.escape(值)
文件“build\bdist.win32\egg\oauthlib\oauth1\rfc5849\utils.py”,第57行,在escape中
'已获取类型为%s的%s。.%(u,类型(u)))
ValueError:只有unicode对象是可转义的。我喜欢这类型。

就这些。

看起来是三个变量赋值末尾的逗号:

Traceback (most recent call last):
  File "C:/Python27/nytimes/20052014/mutliple keyword from multiple user search.py", line 44, in <module>
    sapi.filter(track=["list_terms"])
  File "build\bdist.win32\egg\tweepy\streaming.py", line 313, in filter
    self._start(async)
  File "build\bdist.win32\egg\tweepy\streaming.py", line 235, in _start
    self._run()
  File "build\bdist.win32\egg\tweepy\streaming.py", line 151, in _run
    timeout=self.timeout, stream=True, auth=auth)
  File "C:\Python27\lib\site-packages\requests-2.1.0-py2.7.egg\requests\sessions.py", line 348, in request
    prep = self.prepare_request(req)
  File "C:\Python27\lib\site-packages\requests-2.1.0-py2.7.egg\requests\sessions.py", line 286, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "C:\Python27\lib\site-packages\requests-2.1.0-py2.7.egg\requests\models.py", line 290, in prepare
    self.prepare_auth(auth, url)
  File "C:\Python27\lib\site-packages\requests-2.1.0-py2.7.egg\requests\models.py", line 469, in prepare_auth
    r = auth(self)
  File "C:\Python27\lib\site-packages\requests_oauthlib-0.4.0-py2.7.egg\requests_oauthlib\oauth1_auth.py", line 63, in __call__
    unicode(r.url), unicode(r.method), r.body or '', r.headers)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\__init__.py", line 280, in sign
    request.oauth_params.append(('oauth_signature', self.get_oauth_signature(request)))
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\__init__.py", line 112, in get_oauth_signature
    uri, headers, body = self._render(request)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\__init__.py", line 186, in _render
    headers = parameters.prepare_headers(request.oauth_params, request.headers, realm=realm)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\utils.py", line 32, in wrapper
    return target(params, *args, **kwargs)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\parameters.py", line 58, in prepare_headers
    escaped_value = utils.escape(value)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\utils.py", line 57, in escape
    'Got %s of type %s.' % (u, type(u)))
ValueError: Only unicode objects are escapable. Got <generator object <genexpr> at 0x03006080> of type <type 'generator'>.

逗号将值转换为元组。出于某种原因,oauth库正在将它们转换为生成器,这导致引发
ValueError

看起来是三个变量赋值末尾的逗号:

Traceback (most recent call last):
  File "C:/Python27/nytimes/20052014/mutliple keyword from multiple user search.py", line 44, in <module>
    sapi.filter(track=["list_terms"])
  File "build\bdist.win32\egg\tweepy\streaming.py", line 313, in filter
    self._start(async)
  File "build\bdist.win32\egg\tweepy\streaming.py", line 235, in _start
    self._run()
  File "build\bdist.win32\egg\tweepy\streaming.py", line 151, in _run
    timeout=self.timeout, stream=True, auth=auth)
  File "C:\Python27\lib\site-packages\requests-2.1.0-py2.7.egg\requests\sessions.py", line 348, in request
    prep = self.prepare_request(req)
  File "C:\Python27\lib\site-packages\requests-2.1.0-py2.7.egg\requests\sessions.py", line 286, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "C:\Python27\lib\site-packages\requests-2.1.0-py2.7.egg\requests\models.py", line 290, in prepare
    self.prepare_auth(auth, url)
  File "C:\Python27\lib\site-packages\requests-2.1.0-py2.7.egg\requests\models.py", line 469, in prepare_auth
    r = auth(self)
  File "C:\Python27\lib\site-packages\requests_oauthlib-0.4.0-py2.7.egg\requests_oauthlib\oauth1_auth.py", line 63, in __call__
    unicode(r.url), unicode(r.method), r.body or '', r.headers)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\__init__.py", line 280, in sign
    request.oauth_params.append(('oauth_signature', self.get_oauth_signature(request)))
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\__init__.py", line 112, in get_oauth_signature
    uri, headers, body = self._render(request)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\__init__.py", line 186, in _render
    headers = parameters.prepare_headers(request.oauth_params, request.headers, realm=realm)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\utils.py", line 32, in wrapper
    return target(params, *args, **kwargs)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\parameters.py", line 58, in prepare_headers
    escaped_value = utils.escape(value)
  File "build\bdist.win32\egg\oauthlib\oauth1\rfc5849\utils.py", line 57, in escape
    'Got %s of type %s.' % (u, type(u)))
ValueError: Only unicode objects are escapable. Got <generator object <genexpr> at 0x03006080> of type <type 'generator'>.

逗号将值转换为元组。由于某种原因,oauth库正在将它们转换为生成器,这导致出现
ValueError

回溯的其余部分在哪里?我试图发布它,但它说它的代码添加了一些上下文,你能编辑它吗?我正在尝试发布它。你的整个问题不应该是代码,也不应该尝试适应所有的文本进入标题!请添加一个介绍性段落,解释您正在尝试做什么,到目前为止您尝试了什么,等等。我已经以某种方式发布了它,但它的格式不正确。很抱歉给您带来不便。这里似乎有一个解决方案:回溯的其余部分在哪里?我正试图发布它,但它说它的代码添加了一些上下文。您可以编辑它吗?我正在尝试发布它。您的整个问题不应该是代码,也不应该尝试将所有文本都放在标题中!请添加一个介绍性段落,解释您正在尝试做什么,到目前为止您尝试了什么,等等。我已经以某种方式发布了它,但它的格式不正确。很抱歉给您带来不便。这里似乎有一个解决方案: