wit-ai / pywit

Python library for Wit.ai
Other
1.45k stars 359 forks source link

WitError: Wit responded with status: 400 (Bad Request) #165

Open harshitmehta opened 2 years ago

harshitmehta commented 2 years ago

I am creating a messenger chatbot and I get the following error.

_> File "/app/app.py", line 87, in webhook

response = client.message(msg=text, context={'session_id':fb_id})

File "/app/.heroku/python/lib/python3.9/site-packages/wit/wit.py", line 69, in message resp = req(self.logger, self.access_token, 'GET', '/message', params)

File "/app/.heroku/python/lib/python3.9/site-packages/wit/wit.py", line 41, in req raise WitError('Wit responded with status: ' + str(rsp.statuscode) + wit.wit.WitError: Wit responded with status: 400 (Bad Request)

I know this is a client error and was raised before however I still cannot resolve it. I am using Server Access Token to create my client.

Also this error is triggered as soon as I enter the webhook.

This is what my webhook looks like:

@app.route('/', methods=['POST'])
def webhook():
    messaging_text = None
    data = request.json
    log(data)
    if data['object'] == 'page':
        for entry in data['entry']:
            messages = entry['messaging']
            if messages[0]:
                message = messages[0]
                fb_id = message['sender']['id']
                text = message['message']['text']
                response = client.message(msg=text, context={'session_id':fb_id})
                handle_message(response=response, fb_id=fb_id)

Kindly help.

yuzh174 commented 2 years ago

@harshitmehta , I will take a look

yuzh174 commented 2 years ago

@harshitmehta, what is the app ID? Have you tried to send the request as a plain HTTP message?