Python/Django使用python-instagram(400)APISubscriptionError-无法访问回调URL

har*_*mkv 5 python django instagram

以前的工作.然后它偶尔开始工作,直到它完全停止工作.

以下是我的订阅代码:

def instagram_realtime_subscribe(event_slug, topic):
    api = InstagramAPI(client_id = CLIENT_ID, client_secret = CLIENT_SECRET)

    r = api.create_subscription(object = 'tag',
                            object_id = topic,
                            aspect = 'media',
                            callback_url = 'http://<domain>/event/%s/import/instagram/realtime'%(event_slug),
                            client_id = CLIENT_ID,
                            client_secret = CLIENT_SECRET
)
Run Code Online (Sandbox Code Playgroud)

以下是我处理来自instagram的GET和POST请求的观点:

def import_instagram_rt(request, slug):
    if request.method == "GET":
        mode = request.GET.get("hub.mode")
        challenge = request.GET.get("hub.challenge")
        verify_token = request.GET.get("hub.verify_token")
        if challenge:
            return HttpResponse(challenge, mimetype='text/html')
        else:
            return HttpResponse("test", mimetype='text/html')
    else:
        x_hub_signature=''
        if request.META.has_key('HTTP_X_HUB_SIGNATURE'):
            x_hub_signature = request.META['HTTP_X_HUB_SIGNATURE']
        raw_response = request.raw_post_data
        data = simplejson.loads(raw_response)
        for update in data:
            fetch_data(slug, update["object_id"])
Run Code Online (Sandbox Code Playgroud)

以下是我的urls.py

url(r'^event/([-\w]+)/import/instagram/realtime$', import_instagram_rt),
Run Code Online (Sandbox Code Playgroud)

这用于工作得很漂亮.然而,它已经停止工作两天了.每当调用订阅函数时,它都会抛出错误:

>>> instagram_realtime_subscribe("cats", "cats")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/ubuntu/webapps/django-projects/imports/views.py", line 687, in instagram_realtime_subscribe
    client_secret = CLIENT_SECRET
  File "/home/ubuntu/webapps/django-projects/local/lib/python2.7/site-packages/instagram/bind.py", line 151, in _call
    return method.execute()
  File "/home/ubuntu/webapps/django-projects/local/lib/python2.7/site-packages/instagram/bind.py", line 143, in execute
    content, next = self._do_api_request(url, method, body, headers)
  File "/home/ubuntu/webapps/django-projects/local/lib/python2.7/site-packages/instagram/bind.py", line 124, in _do_api_request
    raise InstagramAPIError(status_code, content_obj['meta']['error_type'], content_obj['meta']['error_message'])
InstagramAPIError: (400) APISubscriptionError-Unable to reach callback URL "http://<domain>/event/cats/import/instagram/realtime".
Run Code Online (Sandbox Code Playgroud)

我尝试手动点击回调URL并得到响应"test",这是你对我编写的函数的期望.我在调用订阅函数之前手动对该url尝试了一个requests.get()并返回了200响应.

当其他人都可以访问时,为什么Instagram无法找到我的回调网址?

har*_*mkv -1

显然,这与代码部分无关。两天后,当我尝试完全相同的代码时,它工作得很好。因此,我认为这个问题是由于某种原因被列入黑名单/速率限制而发生的。我不知道 Instagram 实时 API 的速率限制是如何工作的。我将把它作为一个新问题发布并链接到这里。