From e2907c0805f02eede401f86270d7cba9e721c5d7 Mon Sep 17 00:00:00 2001 From: Georgy Krasulya Date: Mon, 8 Feb 2021 23:38:31 +0800 Subject: [PATCH 1/3] Fix __api_url_params method Use "&" as concatenator in `api_url` if it already has params --- pycoingecko/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycoingecko/api.py b/pycoingecko/api.py index 5785113..15c66b4 100644 --- a/pycoingecko/api.py +++ b/pycoingecko/api.py @@ -39,7 +39,7 @@ def __request(self, url): def __api_url_params(self, api_url, params): if params: - api_url += '?' + api_url += '&' if '?' in api_url else '?' for key, value in params.items(): api_url += "{0}={1}&".format(key, value) api_url = api_url[:-1] From 99468a66314bce5d45c0f2b72fd814d961394e94 Mon Sep 17 00:00:00 2001 From: Manolis Christoforou Date: Tue, 30 Mar 2021 14:13:16 +0300 Subject: [PATCH 2/3] fix __api_url_params issue --- pycoingecko/api.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pycoingecko/api.py b/pycoingecko/api.py index 15c66b4..fa66388 100644 --- a/pycoingecko/api.py +++ b/pycoingecko/api.py @@ -37,9 +37,13 @@ def __request(self, url): # pass raise - def __api_url_params(self, api_url, params): + def __api_url_params(self, api_url, params, api_url_has_params=False): if params: - api_url += '&' if '?' in api_url else '?' + # if api_url contains already params and there is already a '?' avoid + # adding second '?' (api_url += '&' if '?' in api_url else '?'); causes + # issues with request parametes (usually for endpoints with required + # arguments passed as parameters) + api_url += '&' if api_url_has_params else '?' for key, value in params.items(): api_url += "{0}={1}&".format(key, value) api_url = api_url[:-1] @@ -152,7 +156,7 @@ def get_coin_market_chart_by_id(self, id, vs_currency, days, **kwargs): """Get historical market data include price, market cap, and 24h volume (granularity auto)""" api_url = '{0}coins/{1}/market_chart?vs_currency={2}&days={3}'.format(self.api_base_url, id, vs_currency, days) - api_url = self.__api_url_params(api_url, kwargs) + api_url = self.__api_url_params(api_url, kwargs, api_url_has_params=True) return self.__request(api_url) @@ -163,7 +167,7 @@ def get_coin_market_chart_range_by_id(self, id, vs_currency, from_timestamp, to_ api_url = '{0}coins/{1}/market_chart/range?vs_currency={2}&from={3}&to={4}'.format(self.api_base_url, id, vs_currency, from_timestamp, to_timestamp) - api_url = self.__api_url_params(api_url, kwargs) + api_url = self.__api_url_params(api_url, kwargs, api_url_has_params=True) return self.__request(api_url) @@ -181,7 +185,7 @@ def get_coin_ohlc_by_id(self, id, vs_currency, days, **kwargs): """Get coin's OHLC""" api_url = '{0}coins/{1}/ohlc?vs_currency={2}&days={3}'.format(self.api_base_url, id, vs_currency, days) - api_url = self.__api_url_params(api_url, kwargs) + api_url = self.__api_url_params(api_url, kwargs, api_url_has_params=True) return self.__request(api_url) @@ -202,7 +206,7 @@ def get_coin_market_chart_from_contract_address_by_id(self, id, contract_address api_url = '{0}coins/{1}/contract/{2}/market_chart/?vs_currency={3}&days={4}'.format(self.api_base_url, id, contract_address, vs_currency, days) - api_url = self.__api_url_params(api_url, kwargs) + api_url = self.__api_url_params(api_url, kwargs, api_url_has_params=True) return self.__request(api_url) From 656f0a929aa65d888ec1c9aa4d1b524314862f46 Mon Sep 17 00:00:00 2001 From: Manolis Christoforou Date: Tue, 30 Mar 2021 15:11:18 +0300 Subject: [PATCH 3/3] updated version and changelog --- CHANGELOG.md | 5 +++++ setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 615cd9c..c55fd6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +1.4.1 / 2021-03-30 +================== + + * fixed __api_url_params issue for optional parametes of few endpoints (such as /coins/{id}/market_chart) + 1.4.0 / 2020-10-03 ================== diff --git a/setup.py b/setup.py index 7d77c07..fb86c4c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setuptools.setup( name='pycoingecko', - version='1.4.0', + version='1.4.1', packages=['pycoingecko',], license='MIT', description = 'Python wrapper around the CoinGecko API',