From 3b1c5c66c41bd58d192c3e7b4f76a35a11fb3c5e Mon Sep 17 00:00:00 2001 From: Elana <19191012+elanals@users.noreply.github.com> Date: Wed, 23 Jun 2021 16:28:07 +0200 Subject: [PATCH 1/2] don't include folderId in create_chart request if it isn't defined --- datawrapper/__main__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/datawrapper/__main__.py b/datawrapper/__main__.py index 4a0cc1b..2104f12 100644 --- a/datawrapper/__main__.py +++ b/datawrapper/__main__.py @@ -151,7 +151,10 @@ def create_chart( _header = self._auth_header _header["content-type"] = "application/json" - _data = {"title": title, "type": chart_type, "folderId": folder_id} + _data = {"title": title, "type": chart_type} + + if folder_id: + _data['folderId'] = folder_id new_chart_response = r.post( url=self._CHARTS_URL, headers=_header, data=json.dumps(_data) @@ -174,7 +177,7 @@ def create_chart( print(f"New chart {chart_info['type']} created!") else: print( - "Chart could not be created, check your authorization credentials (access token)" + f"Chart could not be created, check your authorization credentials (access token){', and that the folder_id is valid (i.e exists, and your account has access to it)' if folder_id else ''}" ) if data is not None: From f0c86d0983ab994bee10dacb9aefe2f0a0d55d02 Mon Sep 17 00:00:00 2001 From: Elana <19191012+elanals@users.noreply.github.com> Date: Wed, 23 Jun 2021 17:35:50 +0200 Subject: [PATCH 2/2] codestyle --- datawrapper/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datawrapper/__main__.py b/datawrapper/__main__.py index 2104f12..ced51c5 100644 --- a/datawrapper/__main__.py +++ b/datawrapper/__main__.py @@ -154,7 +154,7 @@ def create_chart( _data = {"title": title, "type": chart_type} if folder_id: - _data['folderId'] = folder_id + _data["folderId"] = folder_id new_chart_response = r.post( url=self._CHARTS_URL, headers=_header, data=json.dumps(_data)