Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 2a3e059

Browse files
committed
add data and files to be present - which is not normall legal, convert code from dict to set for files data to improve requests() handling
1 parent 10455f3 commit 2a3e059

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

CloudFlare/cloudflare.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,21 @@ def _add_headers(self, method, content_type, data, files):
9898
if self.headers['Content-Type'] == 'application/json' and isinstance(data, (bytes,bytearray)):
9999
# passing binary file vs JSON
100100
self.headers['Content-Type'] = 'application/octet-stream'
101-
if data and self.headers['Content-Type'] == 'multipart/form-data':
101+
if data and len(data) > 0 and self.headers['Content-Type'] == 'multipart/form-data':
102102
# convert from params to files (i.e multipart/form-data)
103-
files = {}
103+
if files is None:
104+
files = set()
104105
for k,v in data.items():
105-
# files[k] = (None, v, 'application/json')
106106
if isinstance(v, (dict, list)):
107-
files[k] = (None, json.dumps(v), 'application/json')
107+
files.add((k, (None, json.dumps(v), 'application/json')))
108108
else:
109-
files[k] = (None, v)
109+
files.add((k, (None, v)))
110110
# we have replaced data's values into files
111111
data = None
112+
if data is not None and len(data) == 0:
113+
data = None
114+
if files is not None and len(files) == 0:
115+
files = None
112116
if data is None and files is None and self.headers['Content-Type'] == 'multipart/form-data':
113117
# can't have zero length multipart/form-data and as there's no data or files; we don't need it
114118
del self.headers['Content-Type']

0 commit comments

Comments
 (0)