Webhook registration failing with error 500 code 131

webhooks
premium

#1

Hi - I use the streaming API to interface to IoT devices, and I am now updating to the new Premium Account Activity API. Yesterday I hit a hurdle with Twitter reporting an error 500 code 131 on the POST request.

I am hosting a Flask server on my internal network with a Public IP address (I have confirmed is accessible). The GET challenge response code is based on the Twitter python reference code. To register the Webhook I use the code below.

Searching the forum shows others experiencing error 500 but mainly on searches, not webhook registration, and the response is to wait and it should go away. I have been experiencing this for over 12hrs now, which suggests more than a temporary Twitter internal error.

Any thoughts or suggestions appreciated.

thanks
Chris.

from TwitterAPI import TwitterAPI

import os

CONSUMER_KEY = os.environ.get('CONSUMER_KEY', None)
CONSUMER_SECRET = os.environ.get('CONSUMER_SECRET', None)

ACCESS_TOKEN = os.environ.get('ACCESS_TOKEN', None)
ACCESS_TOKEN_SECRET = os.environ.get('ACCESS_TOKEN_SECRET', None)

ENVNAME = os.environ.get('ENVNAME', None)
WEBHOOK_URL = os.environ.get('WEBHOOK_URL', None)

twitterAPI = TwitterAPI(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
response = twitterAPI.request('account_activity/all/:%s/webhooks' % ENVNAME, {'url': WEBHOOK_URL})

print (response.status_code)
print (resposne.text)

#2

With further testing I believe this is related to either 1) having a self signed certificate, or 2) the self-signed certificate did not include www.mydomain.com. It only had mydomain.com.

I have now moved to a letsencrypt certificate with mydomain.com and www.mydomain.com, and after further debugging it’s now working.

I cannot be 100% sure the certificate was the cause, but I believe it was. Hope this helps someone else.

Regards
Chris.