@@ -56,7 +56,7 @@ def call_with_auth(self, method,
5656 api_call_part2 = None ,
5757 api_call_part3 = None ,
5858 identifier1 = None , identifier2 = None , identifier3 = None ,
59- params = None , data = None ):
59+ params = None , data = None , files = None ):
6060 """ Cloudflare v4 API"""
6161
6262 if self .email is '' or self .token is '' :
@@ -65,12 +65,17 @@ def call_with_auth(self, method,
6565 'User-Agent' : self .user_agent ,
6666 'X-Auth-Email' : self .email ,
6767 'X-Auth-Key' : self .token ,
68- 'Content-Type' : 'application/json '
68+ 'Content-Type' : 'multipart/form-data '
6969 }
70+ if files :
71+ # overwrite Content-Type as we are uploading data
72+ headers ['Content-Type' ] = 'multipart/form-data'
73+ # however something isn't right and this works ... look at again later!
74+ del headers ['Content-Type' ]
7075 return self ._call (method , headers ,
7176 api_call_part1 , api_call_part2 , api_call_part3 ,
7277 identifier1 , identifier2 , identifier3 ,
73- params , data )
78+ params , data , files )
7479
7580 def call_with_certauth (self , method ,
7681 api_call_part1 ,
@@ -84,8 +89,8 @@ def call_with_certauth(self, method,
8489 raise CloudFlareAPIError (0 , 'no cert token defined' )
8590 headers = {
8691 'User-Agent' : self .user_agent ,
87- 'X-Auth-User-Service-Key' : self .certtoken ,
88- 'Content-Type' : 'application/json'
92+ 'X-Auth-User-Service-Key' : self .certtoken ,
93+ 'Content-Type' : 'application/json'
8994 }
9095 return self ._call (method , headers ,
9196 api_call_part1 , api_call_part2 , api_call_part3 ,
@@ -95,7 +100,7 @@ def call_with_certauth(self, method,
95100 def _raw (self , method , headers ,
96101 api_call_part1 , api_call_part2 = None , api_call_part3 = None ,
97102 identifier1 = None , identifier2 = None , identifier3 = None ,
98- params = None , data = None ):
103+ params = None , data = None , files = None ):
99104 """ Cloudflare v4 API"""
100105
101106 if self .logger :
@@ -107,6 +112,8 @@ def _raw(self, method, headers,
107112 str (identifier3 )))
108113 self .logger .debug ('Call: optional params and data %s %s' % (str (params ),
109114 str (data )))
115+ if files :
116+ self .logger .debug ('Call: upload file %r' % (files ))
110117
111118 if (method is None ) or (api_call_part1 is None ):
112119 # should never happen
@@ -152,7 +159,7 @@ def _raw(self, method, headers,
152159 if method == 'GET' :
153160 response = requests .get (url , headers = headers , params = params , data = data )
154161 elif method == 'POST' :
155- response = requests .post (url , headers = headers , params = params , json = data )
162+ response = requests .post (url , headers = headers , params = params , json = data , files = files )
156163 elif method == 'PUT' :
157164 response = requests .put (url , headers = headers , params = params , json = data )
158165 elif method == 'DELETE' :
@@ -188,13 +195,13 @@ def _call(self, method, headers,
188195 api_call_part2 = None ,
189196 api_call_part3 = None ,
190197 identifier1 = None , identifier2 = None , identifier3 = None ,
191- params = None , data = None ):
198+ params = None , data = None , files = None ):
192199 """ Cloudflare v4 API"""
193200
194201 response_data = self ._raw (method , headers ,
195202 api_call_part1 , api_call_part2 , api_call_part3 ,
196203 identifier1 , identifier2 , identifier3 ,
197- params , data )
204+ params , data , files )
198205
199206 # Sanatize the returned results - just in case API is messed up
200207 if 'success' not in response_data :
@@ -363,15 +370,15 @@ def patch(self, identifier1=None, identifier2=None, identifier3=None, params=Non
363370 identifier1 , identifier2 , identifier3 ,
364371 params , data )
365372
366- def post (self , identifier1 = None , identifier2 = None , identifier3 = None , params = None , data = None ):
373+ def post (self , identifier1 = None , identifier2 = None , identifier3 = None , params = None , data = None , files = None ):
367374 """ Cloudflare v4 API"""
368375
369376 return self ._base .call_with_auth ('POST' ,
370377 self .api_call_part1 ,
371378 self .api_call_part2 ,
372379 self .api_call_part3 ,
373380 identifier1 , identifier2 , identifier3 ,
374- params , data )
381+ params , data , files )
375382
376383 def put (self , identifier1 = None , identifier2 = None , identifier3 = None , params = None , data = None ):
377384 """ Cloudflare v4 API"""
0 commit comments