diff --git a/elog/logbook.py b/elog/logbook.py index e3b205b..f439c2a 100644 --- a/elog/logbook.py +++ b/elog/logbook.py @@ -333,6 +333,13 @@ def search(self, search_term, n_results=20, scope="subtext"): params.update(search_term) else: params.update({scope: search_term}) + + # Remove empty entries from params, since ELog will redirect such requests + # and remove them anyway, but the redirect leads to unexpected results + keys = list(params.keys()) + for key in keys: + if params[key] == "": + params.pop(key) try: response = requests.get(self._url, params=params, headers=request_headers, diff --git a/tests/test_logbook.py b/tests/test_logbook.py index 62451b0..70f525c 100644 --- a/tests/test_logbook.py +++ b/tests/test_logbook.py @@ -41,6 +41,16 @@ def test_search(self): logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') ids = logbook.search("Powersupply") print(ids) + + def test_search_empty(self): + logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') + ids = logbook.search("") + print(ids) + + def test_search_dict(self): + logbook = elog.open('https://elog-gfa.psi.ch/SwissFEL+test/') + ids = logbook.search({"subtext": "Powersupply"}) + print(ids) if __name__ == '__main__':