python - 无法通过 instagram api 登录 (instagrapi) 的 429 错误(请求太多)

标签 python instagram httpresponse instagram-api response-headers

我需要帮助来动态计算我对 Instagram API 的登录请求的 Retry-After 时间。我想知道我的 IP 是否已在我的桌面上被禁止,但是我认为这不是问题,因为它在我的手机/笔记本电脑上尝试调用时也不起作用。我也尝试登录不同的 instagram 帐户,但这给了我同样的错误。鉴于这些,它让我相信它是代码本身的东西,而不是我的帐户

我的 story_upload 函数,它只被调用一次,所以它不应该使服务器过载:

 def upload_post():
      cl = Client()
      cl.login("username", "password")
      image_path = "/home/Spotify365/mysite/static/images/testing.png"
      cl.photo_upload_to_story(path=image_path, caption="Generated Automatically by Spotify365", links=[StoryLink(webUri='https://spotify365.pythonanywhere.com/')])

完整的错误日志:(成功,直到它尝试登录 API,引发错误 429)

2021-04-01 12:52:15,655: username [200] POST https://i.instagram.com/api/v1/accounts/contact_point_prefill/ (169.3.0.30.135, Xiaomi capricorn)
2021-04-01 12:52:15,711: username [200] POST https://i.instagram.com/api/v1/accounts/get_prefill_candidates/ (169.3.0.30.135, Xiaomi capricorn)
2021-04-01 12:52:15,747: username [200] POST https://i.instagram.com/api/v1/accounts/contact_point_prefill/ (169.3.0.30.135, Xiaomi capricorn)
2021-04-01 12:52:15,800: username [200] POST https://i.instagram.com/api/v1/launcher/sync/ (169.3.0.30.135, Xiaomi capricorn)
2021-04-01 12:52:15,878: username [200] POST https://i.instagram.com/api/v1/qe/sync/ (169.3.0.30.135, Xiaomi capricorn)
2021-04-01 12:52:15,982: username [429] POST https://i.instagram.com/api/v1/accounts/login/ (169.3.0.30.135, Xiaomi capricorn)
2021-04-01 12:52:15,982: Status 429: Too many requests
2021-04-01 12:52:15,983: Exception on /instaStory [GET]
Traceback (most recent call last):
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 183, in _send_private_request
    response.raise_for_status()
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: - for url: https://i.instagram.com/api/v1/accounts/login/
**NO MATCH**
During handling of the above exception, another exception occurred:
**NO MATCH**
Traceback (most recent call last):
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/Spotify365/mysite/flask_app.py", line 50, in isStory
    upload_post()
  File "/home/Spotify365/mysite/flask_app.py", line 43, in upload_post
    cl.login("username", "password")
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/instagrapi/mixins/auth.py", line 341, in login
    if self.private_request("accounts/login/", data, login=True):
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 316, in private_request
    raise e
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 303, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "/home/Spotify365/.virtualenvs/myenv/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 244, in _send_private_request
    raise PleaseWaitFewMinutes(e, response=e.response, **last_json)
instagrapi.exceptions.PleaseWaitFewMinutes: Please wait a few minutes before you try again.

我尝试调用 jqXHR.getAllResponseHeaders() 以希望获得“Retry-After” header ,但这并没有真正帮助我:

connection: keep-alive
content-length: 290
content-type: text/html; charset=utf-8
date: Thu, 01 Apr 2021 13:13:42 GMT
server: PythonAnywhere

最佳答案

429 错误已在 instagrapi 1.7.0 中修复

关于python - 无法通过 instagram api 登录 (instagrapi) 的 429 错误(请求太多),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66907508/

相关文章:

python 结构包 double

ios - 获取 PHAsset 的本地文件路径

android - Instagram 分享照片/视频

angular - 如何在Angular HTTP中获得临时响应-ArrayBuffer

android - 在 Webview 中加载一个 Url 并得到它的响应

python - 几分钟后 numpy plot 创建图形失败 idel

python - 给定一个数字,找到到达它的序列

python - 谷歌应用引擎/WSGIApplication : How to check debug?

instagram - 1080x1080 照片通过 Instagram API

spring-mvc - 如何在 Spring MVC 中代理 HTTP 请求?