diff --git a/CHANGES.md b/CHANGES.md index 1b4f713..19b46f2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,14 @@ +## v3.2 + +- Fixed request keyword arguments issue +- Better error messages + +## v3.1 + +- Added `examples/template.py` +- Fixed missing type +- Updated `examples/weather.py` to `examples/quickstart.py` to reflect the docs + ## v3.0 Bot Engine integration diff --git a/setup.py b/setup.py index c8342dc..662dc4d 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ setup( name='wit', - version='3.1', + version='3.2', description='Wit SDK for Python', author='The Wit Team', author_email='help@wit.ai', diff --git a/wit/wit.py b/wit/wit.py index 4206863..83160b4 100644 --- a/wit/wit.py +++ b/wit/wit.py @@ -9,7 +9,7 @@ class WitError(Exception): pass -def req(access_token, meth, path, params, payload=None): +def req(access_token, meth, path, params, **kwargs): rsp = requests.request( meth, WIT_API_HOST + path, @@ -18,9 +18,14 @@ def req(access_token, meth, path, params, payload=None): 'accept': 'application/vnd.wit.20160330+json' }, params=params, - json=payload, + **kwargs ) - return rsp.json() + if rsp.status_code > 200: + raise Exception('Wit responded with status: ' + str(rsp.status_code) + ' (' + rsp.reason + ')') + json = rsp.json() + if 'error' in json: + raise WitError('Wit responded with an error: ' + json['error']) + return json def validate_actions(actions): @@ -54,7 +59,7 @@ def converse(self, session_id, message, context={}): params = {'session_id': session_id} if message: params['q'] = message - return req(self.access_token, 'POST', '/converse', params, context) + return req(self.access_token, 'POST', '/converse', params, json=context) def run_actions(self, session_id, message, context={}, max_steps=DEFAULT_MAX_STEPS):