From f3467bca36d8f9de95f9c5a5c36c26b61b57530b Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 18 Jun 2019 15:33:59 +0300 Subject: [PATCH] Use POST for writes (with api_sig), GET for reads --- src/pylast/__init__.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/pylast/__init__.py b/src/pylast/__init__.py index 1341de0..11bf1d8 100644 --- a/src/pylast/__init__.py +++ b/src/pylast/__init__.py @@ -904,6 +904,13 @@ class _Request: data.append("=".join((name, quote_plus(_string(self.params[name]))))) data = "&".join(data) + if "api_sig" in self.params.keys(): + method = "POST" + url_parameters = "" + else: + method = "GET" + url_parameters = "?" + data + headers = { "Content-type": "application/x-www-form-urlencoded", "Accept-Charset": "utf-8", @@ -921,8 +928,8 @@ class _Request: try: conn.request( - method="POST", - url="https://" + host_name + host_subdir, + method=method, + url="https://" + host_name + host_subdir + url_parameters, body=data, headers=headers, ) @@ -933,7 +940,12 @@ class _Request: conn = HTTPSConnection(context=SSL_CONTEXT, host=host_name) try: - conn.request(method="POST", url=host_subdir, body=data, headers=headers) + conn.request( + method=method, + url=host_subdir + url_parameters, + body=data, + headers=headers, + ) except Exception as e: raise NetworkError(self.network, e) from e