Python中文
首页
教程
问答
标签
搜索
登录
注册
使用Tweepy收集tweet时“RuntimeError:cmp中超过了最大递归深度”
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在尝试使用tweepy从twitter api收集大量tweets。我有一个文本文件,包含大约一万个tweet id。我的程序读取文件,抓取每个tweet,以及它正在回复的tweet。然后,它将每条tweet的文本以及每个作者的用户名保存在各自的文本文件中。代码如下:</p> <pre><code>auth = tweepy.OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) api = tweepy.API(auth) tweetsFile = open("srcstic.txt", "r") tweets_seen = set() # holds tweets already seen def getNextLine(): while True: tweetID = tweetsFile.readline() getTweetObj(tweetID) if not tweetID: break def getTweetObj(tweetID): try: tweetObj = api.get_status(tweetID) #sleep(11) except tweepy.error.TweepError: getNextLine() else: pass tweet = tweetObj.text.encode("utf8") idnum = tweetObj.in_reply_to_status_id_str try: former = api.get_status(idnum) except tweepy.error.TweepError: getNextLine() else: printFiles(former, tweetObj, tweet) def printFiles(former, tweetObj, tweet): callUserName = former.user.screen_name responseUserName = tweetObj.user.screen_name if tweet not in tweets_seen: with open("callauthors.txt", "a") as callauthors: cauthors = callUserName + "\n" callauthors.write(cauthors) with open("responseauthors.txt", "a") as responseauthors: rauthors = responseUserName + "\n" responseauthors.write(rauthors) with open("response_tweets.txt", "a") as responsetweets: output = (tweetObj.text.encode('utf-8')+"\n") responsetweets.write(output) with open("call_tweets.txt", "a") as calltweets: output = (former.text.encode('utf-8')+"\n") calltweets.write(output) tweets_seen.add(tweet) getNextLine() </code></pre> <p>但是,在一段时间内一切正常,然后我得到以下错误:</p> ^{pr2}$ <p>有什么问题吗? 谢谢。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你只能递归地调用一个函数999次之后,你得到了那个错误。您可以改为使用条件语句从函数外部调用或创建生成器。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
无法使用Django/mongoengine连接到MongoDB(身份验证失败)
6 回答
无法使用Django\u mssql\u后端迁移到外部hos
8 回答
无法使用Django&Python3.4连接到MySql
10 回答
无法使用Django+nginx上载媒体文件
3 回答
无法使用Django1.6导入名称模式
6 回答
无法使用Django1.7和mongodb登录管理站点
7 回答
无法使用Djangoadmin创建项目,进程使用了错误的路径,因为我事先安装了错误的Python
10 回答
无法使用Djangockedi验证CBV中的字段
8 回答
无法使用Djangocketditor上载图像(错误400)
9 回答
无法使用Djangocron进行函数调用
2 回答
无法使用Djangofiler djang上载文件
2 回答
无法使用Djangokronos
5 回答
无法使用Djangomssql provid
8 回答
无法使用Djangomssql连接到带有Django 1.11的MS SQL Server 2016
1 回答
无法使用Djangomssq迁移Django数据库
4 回答
无法使用Djangonox创建用户
10 回答
无法使用Djangopyodb从Django查询SQL Server
4 回答
无法使用Djangopython3ldap连接到ldap
4 回答
无法使用Djangoredis连接到redis
5 回答
无法使用Django中的FK创建新表
3 回答