Non-200 response code #1
Comments
Hi Fabio, 214 is a Host key error, so is there something you're doing with the request key that could mangle it in some way? I'll post an example from one of my implementations, which I've meant to do for a long time. |
I'm thinking that this is either a issue with using tweepy with an aiohttp web server or something that tweepy is doing 🤔 I'm using ngrok to forward my traffic on port 8080 - where the server is running. I'm setting the route as mentioned in aiohttp: My get handler looks like this (I've changed it around so many times tho, I've used the twitter example, your example and a misture in between) async def handle_get(self, request):
"""Handle Twitter get request."""
crc_token = request.rel_url.query.get('crc_token')
sha256_hash_digest = hmac.new(self.consumer_secret.encode(), msg=crc_token.encode(), digestmod=hashlib.sha256).digest()
_LOGGER.info(sha256_hash_digest)
# construct response data with base64 encoded hash
response = {
'response_token': 'sha256=' + base64.b64encode(sha256_hash_digest).decode('utf-8')
}
_LOGGER.info(response)
return aiohttp.web.Response(status=200, body=json.dumps(response), headers={'Content-Type': 'application/json'}) Then I am setting tweepy and your code like you wrote on the docs (on that PR that isn't merged yet) async def listen(self):
"""Listen is handled by webhook."""
#self.base_url == ngrok URL
# self.name == twitter (or other thing set in config)
opsdroid_url = f"{self.base_url}/connector/{self.name}"
auth = tweepy.OAuthHandler(self.consumer_key, self.consumer_secret)
auth.set_access_token(self.access_token, self.access_token_secret)
api = ActivityAPI(auth)
#Try/except was just so the server wouldn't crash due to unhandled tweepy exception
try:
activityResponse = api.enable_activity(url=opsdroid_url, env=self.env)
except Exception as e:
_LOGGER.info(e) The weird thing is, when I run the server, ngrok shows a 502 error straight away before we get the error that I mentioned: |
I haven't used aiohttp I'll take a look tomorrow but the 502 is a clue I think. It suggests there's a failure in proxying, tweepy might be treating that as a key failure. S |
The interfaces you've published to twitter are all to port 8080, so they're not https but http, or are they https? Either way you're listening on whatever local port using aiohttp. The 502 is reported by the ngrok tunnel to the twitter API, is it the initial leg of the 3 legged dance? Or the returned access code, or the validation step? |
Is it only the AccountActivity call that fails? Does the initial authorise flow work? |
Hello Simon,
thanks for creating this, I've been around twitter API docs and other libraries to try and get the webhooks working for ages now...
I've copied your code to test it out, although I keep getting this error:
I'm passing my URL and env as expected. I've also checked that the endpoint is working and all seems good. Just wanted to check with you if you have any idea on how I could try to debug this? At the moment I'm out of ideas haha
Thank you
The text was updated successfully, but these errors were encountered: