Skip to content

Commit bbac63d

Browse files
committed
started using requests.session
1 parent 0358422 commit bbac63d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

examples/retrieve_and_rank_v1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# print(json.dumps(created_cluster, indent=2))
1616

1717
# Replace with your own solr_cluster_id
18-
solr_cluster_id = 'sc19cac12e_3587_4510_820d_87945c51a3f9'
18+
solr_cluster_id = 'sc573c955c_4bb3_46b2_bada_d8040c8c058d'
1919

2020
status = retrieve_and_rank.get_solr_cluster_status(solr_cluster_id=solr_cluster_id)
2121
print(json.dumps(status, indent=2))
@@ -31,14 +31,14 @@
3131
configs = retrieve_and_rank.list_configs(solr_cluster_id=solr_cluster_id)
3232
print(json.dumps(configs, indent=2))
3333

34-
# collection = retrieve_and_rank.create_collection(solr_cluster_id, 'test-collection', 'test-config')
35-
# print(json.dumps(collection, indent=2))
34+
collection = retrieve_and_rank.create_collection(solr_cluster_id, 'test-collection', 'test-config')
35+
print(json.dumps(collection, indent=2))
3636

3737
if len(configs['solr_configs']) > 0:
3838
collections = retrieve_and_rank.list_collections(solr_cluster_id=solr_cluster_id)
3939
print(json.dumps(collections, indent=2))
4040

41-
pysolr_client = retrieve_and_rank.get_pysolr_client(solr_cluster_id, 'example-collection')
41+
pysolr_client = retrieve_and_rank.get_pysolr_client(solr_cluster_id, 'test-collection')
4242
results = pysolr_client.search('bananas')
4343
print('{0} documents found'.format(len(results.docs)))
4444

watson_developer_cloud/watson_developer_cloud_service.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, vcap_services_name, url, username=None, password=None, use_vc
7575
"""
7676

7777
self.url = url
78-
self.jar = None
78+
self.session = None
7979
self.api_key = None
8080
self.username = None
8181
self.password = None
@@ -112,14 +112,14 @@ def set_username_and_password(self, username=None, password=None):
112112

113113
self.username = username
114114
self.password = password
115-
self.jar = CookieJar()
115+
self.session = requests.Session()
116116

117117
def set_api_key(self, api_key):
118118
if api_key == 'YOUR API KEY':
119119
api_key = None
120120

121121
self.api_key = api_key
122-
self.jar = CookieJar()
122+
self.session = requests.Session()
123123

124124
def set_url(self, url):
125125
self.url = url
@@ -239,8 +239,8 @@ def request(self, method, url, accept_json=False, headers=None, params=None, jso
239239
else:
240240
params['api_key'] = self.api_key
241241

242-
response = requests.request(method=method, url=full_url, cookies=self.jar, auth=auth, headers=headers,
243-
params=params, data=data, files=files, **kwargs)
242+
response = self.session.request(method=method, url=full_url, auth=auth, headers=headers,
243+
params=params, data=data, files=files, **kwargs)
244244

245245
if 200 <= response.status_code <= 299:
246246
if accept_json:

0 commit comments

Comments
 (0)