Skip to content

Commit

Permalink
fixing keyword args in request + better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
patapizza committed Apr 14, 2016
1 parent 9820988 commit 35c4b2f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

setup(
name='wit',
version='3.1',
version='3.2',
description='Wit SDK for Python',
author='The Wit Team',
author_email='[email protected]',
Expand Down
13 changes: 9 additions & 4 deletions wit/wit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

1 comment on commit 35c4b2f

@patapizza
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#20

Please sign in to comment.