Skip to content

Commit a8d013a

Browse files
author
Alex Pana
committed
Added comments and specific error catching
1 parent 60258e7 commit a8d013a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

samples/group_filtering.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,29 @@ def main():
4444
group1 = TSC.GroupItem(group_name)
4545
group1 = server.groups.create(group1)
4646
print(group1)
47-
except:
48-
print('Group \'%s\' already existed' % group_name)
47+
except TSC.ServerResponseError:
48+
print('Group \'%s\' already existed' % group_name)
4949

5050
group_name = 'SALES ROMANIA'
5151
# Try to create a group named "SALES ROMANIA"
5252
try:
5353
group2 = TSC.GroupItem(group_name)
5454
group2 = server.groups.create(group2)
5555
print(group2)
56-
except:
56+
except TSC.ServerResponseError:
5757
print('Group \'%s\' already existed' % group_name)
5858

59-
group_name = 'SALES+ROMANIA'
59+
# URL Encode the name of the group that we want to filter on
60+
# i.e. turn spaces into plus signs
61+
filter_group_name = 'SALES+ROMANIA'
6062
options = TSC.RequestOptions()
6163
options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
6264
TSC.RequestOptions.Operator.Equals,
63-
group_name))
65+
filter_group_name))
6466

6567
filtered_group_paged = server.groups.get(req_options=options)
68+
69+
# Return type is a tuple with the first entry as a list of matching groups
6670
print(filtered_group_paged[0][0].name)
6771

6872
options = TSC.RequestOptions()

0 commit comments

Comments
 (0)