如何修复Tweepy / Python错误'404'和'34'

时间:2019-04-26 11:49:10

标签: python tweepy

从下面的脚本正常运行中获取错误。所有其他脚本都可以连接并正常工作。

错误:

  

回溯(最近通话最近):文件   “ C:... \ Python \ Python36 \ lib \ site-packages \ twitter \ api.py”,第341行,在   _handle_response句柄= urllib_request.urlopen(req,** kwargs)

     

文件“ C:... \ Python \ Python36 \ lib \ urllib \ request.py”,第223行,在   urlopen返回opener.open(URL,数据,超时)

     

文件“ C:... \ Python \ Python36 \ lib \ urllib \ request.py”,第532行,处于打开状态   响应= meth(req,响应)文件   “ C:... \ Python \ Python36 \ lib \ urllib \ request.py”,第642行,在   http_response'http',请求,响应,代码,msg,hdr)文件   “ C:... \ Python \ Python36 \ lib \ urllib \ request.py”,第570行,错误   返回self._call_chain(* args)

     

文件“ C:... \ Python \ Python36 \ lib \ urllib \ request.py”,第504行,在   _call_chain结果= func(* args)

     

文件“ C:... \ Python \ Python36 \ lib \ urllib \ request.py”,第650行,在   http_error_default引发HTTPError(req.full_url,code,msg,hdrs,fp)   urllib.error.HTTPError:HTTP错误404:未找到

     

在处理上述异常期间,发生了另一个异常:

     

回溯(最近通话最近一次):

     

文件“ C:\ TwitterFollow \ TwitterFollow.py”,第15行,在   my_bot.auto_follow_followers_of_user(“ UserName”,count = 200)

     

文件“ C:\ TwitterFollow \ TwitterFollow__init __。py”,第334行,在   auto_follow_followers_of_user followers_of_user =   设置(self.TWITTER_CONNECTION.followers.ids(screen_name = user_screen_name   [“ ids”] [:count])

     

文件“ C:... \ Python \ Python36 \ lib \ site-packages \ twitter \ api.py”,行   334,在__call__return self._handle_response(req,uri,arg_data,   _timeout)

     

文件“ C:... \ Python \ Python36 \ lib \ site-packages \ twitter \ api.py”,行   367,在_handle_response中引发TwitterHTTPError(e,uri,self.format,   arg_data)twitter.api.TwitterHTTPError:Twitter的状态发送为404   URL:1.1 / followers / ids.json使用参数   (oauth_consumer_key = xxx ... xxx&oauth_nonce = xxx ... xxx&oauth_signature_method = xxx ... xxx&oauth_timestamp = xxx ... xxx&oauth_token = xxx ... xxx&oauth_version = 1.0&screen_name = UserName%E2%80%8F&oauth_signature = xxx ... xxx)   详细信息:{'错误':[{'代码':34,'消息':'对不起,该页面确实   不存在。'}]}

代码:

#Follows the followers of a specified user.
def auto_follow_followers_of_user(self, user_screen_name, count=200):
    following = self.get_follows_list()
    followers_of_user = set(self.TWITTER_CONNECTION.followers.ids(screen_name=user_screen_name)["ids"][:count])
    do_not_follow = self.get_do_not_follow_list()

    for user_id in followers_of_user:
        try:
            if (user_id not in following and
                user_id not in do_not_follow):
                self.TWITTER_CONNECTION.friendships.create(user_id=user_id, follow=False)
                print("following %s" % user_id)
                # add delay
                time.sleep(randint(10,100))

        except TwitterHTTPError as e:
            # quit on rate limit errors.                                                                                                                  
            if "unable to follow more people at this time" in str(e).lower():
                print("You are unable to follow more people at this time. "
                      "Wait a while before running the bot again or gain more followers.")
                return

            # do not print "already requested to follow" errors.
            if "already requested to follow" not in str(e).lower():

0 个答案:

没有答案