使用Instaloader通过用户名获取用户资料时遭遇429错误求助
解决Instaloader反复触发429请求过多错误的方案
问题场景
使用Instaloader获取Instagram用户资料,代码如下:
import instaloader ACCOUNT_USERNAME="" ACCOUNT_PASSWORD="" # 创建Instaloader实例 bot = instaloader.Instaloader() bot.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD) username = "instagram" profile = instaloader.Profile.from_username(bot.context, username) print("Trying to scrape profile of:", profile.username) print("Number of Posts: ", profile.mediacount) print("Followers Count: ", profile.followers) print("Following Count: ", profile.followees)
运行后反复出现以下错误,即使等待30分钟重试也无法解决:
HTTP redirect from https://i.instagram.com/api/v1/users/web_profile_info/?username=instagram to Number of requests within last 10/11/20/22/30/60 minutes grouped by type:
other: 1 1 1 1 1 1
iphone: 1 1 1 1 1 1Instagram responded with HTTP error "429 - Too Many Requests". Please
do not run multiple instances of Instaloader in parallel or within
short sequence. Also, do not use any Instagram App while Instaloader
is running.
The request will be retried in 30 minutes, at 18:04.
可落地的解决办法
- 暂停所有Instagram账号操作:运行Instaloader期间,不要使用手机端、网页端的同一Ins账号,避免账号请求量叠加触发限制。
- 添加请求速率限制:初始化Instaloader时配置速率控制器,降低请求频率,示例:
也可以手动在关键请求步骤之间添加延迟:from instaloader import RateController bot = instaloader.Instaloader(rate_controller=RateController(per_minute=3))import time # 获取资料前添加延迟 time.sleep(10) profile = instaloader.Profile.from_username(bot.context, username) - 复用登录会话:第一次登录后保存会话文件,后续直接加载会话,避免重复登录触发验证和请求限制:
bot = instaloader.Instaloader() try: bot.load_session_from_file(ACCOUNT_USERNAME) except FileNotFoundError: bot.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD) bot.save_session_to_file() - 排查重复运行的脚本:确认没有同时启动多个Instaloader实例,也没有代码中存在循环逻辑导致重复发送请求。
- 切换网络IP:如果是IP层面的限制,尝试更换网络(比如从WiFi切换到手机热点),避免IP被标记为高频请求源。
- 更新Instaloader版本:旧版本可能适配性不足,执行命令更新到最新版:
pip install --upgrade instaloader
内容的提问来源于stack exchange,提问作者Yash Chauhan
相关产品推荐
相关产品推荐

