我正在尝试使用 python 和 Tweepy 获取 Twitter 关注者数据。但是我经常遇到异常,不知道为什么会发生以及如何处理。有人可以帮我解决这个问题。另外,当光标获取帐户中的最后一个关注者时,如何停止循环。
错误:TTPSConnectionPool(host='api.twitter.com', port=443): url: /1.1/followers/list.json?cursor=1516792635609098963&id=%40Careers (Caused by ProxyError('Cannot connect to proxy) .', OSError('Tunnel connection failed: 407 Proxy Authentication Required',)))
代码
def process_follower(follower,i):
Mycode
consumer_key = '*********'
consumer_secret = ''********''
access_token = ''********************''
access_token_secret = ''************''
import sys
import os
import tweepy
import time
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
get_user_to_query = 'Accountname'
f = open('Account_followers_Location04012017.json', 'w', encoding='utf-8', errors="surrogateescape")
try:
for follower in tweepy.Cursor(api.followers, id = get_user_to_query).items():
#print(follower.name)
process_follower(follower, i)
except Exception as e:
print(e)
f.close()