以前工作正常。然后它偶尔开始工作,直到完全停止工作。

以下是我的订阅代码:

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
)

以下是我处理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"])

以下是我的urls.py
url(r'^event/([-\w]+)/import/instagram/realtime$', import_instagram_rt),

这用于精美地工作。但是,从两天后开始停止工作。每当调用订阅函数时,它都会引发错误:
>>> 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".

我尝试手动点击Callback URL,并得到响应“test”,这是您从我编写的函数中所期望的。在调用订阅功能之前,我手动尝试了对该URL的request.get()并返回了200响应。

当其他所有人都可以访问它时,Instagram为什么找不到我的回调URL?

最佳答案

我认为没有调用import_instagram_rt,因为它们“无法访问回调URL”。
让我们分解一下,当他们尝试到达您的回调URL时会发生什么。
他们解析URL
您的网址格式正确吗? http://<domain>/event/cats/import/instagram/realtime不是,但是我认为您正在隐藏真实的主机名。 ;-)
他们解析主机名
您的DNS可以吗?您是否对区域进行了任何更新并弄乱了序列号?主服务器和辅助服务器之间的区域传输是否正常运行? “偶尔工作”可能意味着某些轮询方案无法正常工作,或者某些DNS服务器给出了错误的答复或超时。
他们在端口80上为您的IP打开一个TCP套接字
您知道演练:SYN, SYN-ACK, ACK。如果由于某些有趣的硬件异常而看到一些轻微的异常,请考虑将其发送到
museum of broken packets
认真地...您的网络中的所有跃点是否都在路由这些数据包,或者是否有防火墙将其丢弃?您是否有包含黑名单和空路由的“有用” ISP?
机器上的进程处理连接
您有接受连接的过程吗?如果您使用gunicorn或类似的WSGI服务器进行服务... run it behind a reverse proxy可以缓冲连接吗?否则,您的工作人员可能会为访客忙上instagram_realtime_subscribe,并阻止来自Instagram的回叫。
该过程以输出为响应
仅在这一点上,您的Django应用程序开始发挥作用。如果import_instagram_rt正确,则将请求路由到urls.py ...
通过日志和tcpdumps进行愉快的狩猎...
聚苯乙烯
为什么将其从问题中删除?

状态503强烈表明您没有可用来处理instagram请求的工作人员...
如果您有1个工作进程,并且heroku代理不缓冲请求,那么当您“尝试手动命中回调URL”时,一个工作进程将按预期方式响应。但是当您的django应用正在处理请求并调用instagram_realtime_subscribe时。那么您的工作人员将一直阻塞,直到它收到来自instagram的响应为止(因为它没有得到),因为instagram正在等待您的工作人员可以处理该回调。这将互相等待,直到发生超时。 503状态可能由代理缓存一会儿。

关于Python/Django使用python-instagram(400)APISubscriptionError-无法访问回调网址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19969476/

10-11 22:31
查看更多