use quote instead of requests' quote_plus
import json
import requests
+from urllib.parse import quote
from .api import Api
@@ -41,20 +42,24 @@ class List(Api):
return res
else:
filters = map(lambda x: '-OR-' if x == 'OR' else x, filters)
- kwargs['params'] = {'search': ''.join(filters)}
+ # requests uses quote_plus to escape the params, but we want to use quote
+ # we're therefore passing a string (won't be escaped again) instead of an object
+ kwargs['params'] = 'search=%s' % quote(''.join(filters))
try:
r = requests.get('%s/%s/' % (url, entity), headers={'Accept': 'application/json;version=%s' % config['version']}, **kwargs)
+ print(r.url)
except Exception as e:
print('Failed to list %s. Please make sure the substrabac instance is live. Detail %s' % (entity, e))
else:
res = ''
try:
res = r.json()
- res = flatten(res) if not is_complex else res
- res = json.dumps(res, indent=2)
except:
res = 'Can\'t decode response value from server to json: %s' % r.content
+ else:
+ res = flatten(res) if not is_complex else res
+ res = json.dumps(res, indent=2)
finally:
print(res)
return res
