简体   繁体   English

AttributeError:在Ubuntu中运行Python tweepy脚本时解码错误

[英]AttributeError: decoding error while running Python tweepy script in Ubuntu

I have a Python 3.5 script which essentially is a Twitter scraper that collects tweets using the tweepy package and its StreamListener function. 我有一个Python 3.5脚本,它实际上是一个Twitter 抓取程序,它使用tweepy包及其StreamListener函数收集推文。

Now my script runs perfectly within the Command shell but when I try to run it on the Ubuntu environment of my server I receive a decoding error. 现在,我的脚本可以在Command Shell中完美运行,但是当我尝试在服务器的Ubuntu环境中运行脚本时,会收到解码错误。

   File "/usr/lib/python3/dist-packages/tweepy/streaming.py", line 445, in filter
self._start(async)
   File "/usr/lib/python3/dist-packages/tweepy/streaming.py", line 361, in _start
self._run()
   File "/usr/lib/python3/dist-packages/tweepy/streaming.py", line 294, in _run
raise exception
   File "/usr/lib/python3/dist-packages/tweepy/streaming.py", line 247, in _run
verify=self.verify)
   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 454, in reque                                                                                                             st
prep = self.prepare_request(req)
   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 388, in prepa                                                                                                             
re_request
hooks=merge_hooks(request.hooks, self.hooks),
   File "/usr/lib/python3/dist-packages/requests/models.py", line 297, in prepare
self.prepare_auth(auth, url)
   File "/usr/lib/python3/dist-packages/requests/models.py", line 490, in prepare                                                                                                             _auth
   r = auth(self)
   File "/usr/lib/python3/dist-packages/requests_oauthlib/oauth1_auth.py", line 7                                                                                                             1, in __call__
r.url = to_native_str(r.url)
   File "/usr/lib/python3/dist-packages/requests_oauthlib/oauth1_auth.py", line 1                                                                                                             4, in to_native_str
return string.decode('utf-8')

AttributeError: 'str' object has no attribute 'decode'

This makes sense because you can't decode a string which already is a string. 这是有道理的,因为您无法解码已经是字符串的字符串。 But my question is how I can solve this issue because this is an error occuring within a package? 但是我的问题是,由于这是程序包内发生的错误,我该如何解决此问题?

It looks like the problem comes from requests-oauthlib , you are running an old version of it, and the problem seems to have been fixed since 4.0.1 . 看来问题出在requests-oauthlib上 ,您正在运行它的旧版本,并且该问题自4.0.1以来似乎已得到解决。

Upgrade your system (the packaged version with Ubuntu 16.10 is 7.0): 升级系统(Ubuntu 16.10的打包版本为7.0):

sudo apt update && apt upgrade

Or install using pip: 或使用pip安装:

sudo pip3 install requests-oauthlib

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM