Registering webhook, gives error with python

oauth
api-access
python
webhooks
django

#1

Hello, trying to register an endpont but gives the following error

‘{“errors”:[{“code”:214,“message”:“Non-200 response code during CRC GET request (i.e. 404, 500, etc).”}]}’

I’ve been researching a lot here and stackoverflow, but there’s no clear explanation of how to achieve this.

My django view (just for testing the webhook register process)

from django.http import JsonResponse
import base64
import hmac
import hashlib
import json

def crc(request):

    cskey = 'my_consumer_secret_key'

    sha256_hash_digest = hmac.new(
        cskey.encode('utf-8'),
        msg=request.GET.get('crc_token'),
        digestmod=hashlib.sha256).digest()

    response = {'response_token': 'sha256=' + base64.b64encode(sha256_hash_digest).decode('utf-8')}

    return JsonResponse(response)

My request:

from requests_oauthlib import OAuth1Session
import urllib

CONSUMER_KEY = 'XXXX'
CONSUMER_SECRET = 'XXXX'
ACCESS_TOKEN = 'XXXX'
ACCESS_SECRET = 'XXXX'

twitter = OAuth1Session(
    CONSUMER_KEY,
    client_secret=CONSUMER_SECRET,
    resource_owner_key=ACCESS_TOKEN,
    resource_owner_secret=ACCESS_SECRET)
webhook_endpoint = urllib.parse.quote_plus('https://<myusername>.pythonanywhere.com')
url = 'https://api.twitter.com/1.1/account_activity/all/testenv/webhooks.json?url={}'.format(webhook_endpoint)
r = twitter.post(url)

What am I doing wrong? I tried adding ‘response_code’ to the JsonResponse but gives the same error.

If I just do a simple requests.get to my url, returns me 200.


closed #2

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.


opened #3

#4

Hi @Colmena90 - did you manage to get this sorted out?