@@ -154,11 +154,12 @@ def request_post_multipart(self, resource, params, files):
154154 selector = "/%s/%s/%s" % (self .api_name , self .api_version , resource )
155155
156156 params = self .set_base_params (params )
157+
157158 content_type , body = self .encode_multipart_formdata (params , files )
158159 conn = HTTPSConnection (host )
159160 conn .putrequest ('POST' , selector )
160- conn .putheader ('content -type' , content_type )
161- conn .putheader ('content -length' , str (len (body )))
161+ conn .putheader ('Content -type' , content_type )
162+ conn .putheader ('Content -length' , str (len (body )))
162163 conn .putheader ('User-Agent' , 'sms-python' )
163164 conn .endheaders ()
164165 conn .send (body )
@@ -188,6 +189,7 @@ def request_post_multipart(self, resource, params, files):
188189 def encode_multipart_formdata (self , params , files ):
189190 boundary = str (uuid .uuid1 ())
190191 crlf = '\r \n '
192+
191193 l = []
192194 for key , value in params .items ():
193195 l .append ('--' + boundary )
@@ -196,41 +198,16 @@ def encode_multipart_formdata(self, params, files):
196198 l .append (value )
197199
198200 for key , value in files .items ():
199-
200- print (self .get_content_type (value ['filename' ]))
201201 l .append ('--' + boundary )
202202 l .append ('Content-Disposition: form-data; name="%s"; filename="%s"' % (key , value ['filename' ]))
203203 l .append ('Content-Type: %s' % self .get_content_type (value ['filename' ]))
204-
205- print (type (value ['content' ]))
206204 l .append ('' )
207205 l .append (str (value ['content' ]))
208206
209207 l .append ('--' + boundary + '--' )
210208 l .append ('' )
211-
212209 body = crlf .join (l ).encode ('utf-8' )
213- """
214- body = body.encode('utf-8')
215-
216- print("WOW")
217- for key, value in files.items():
218- print(self.get_content_type(value['filename']))
219- image_data = '--' + boundary + crlf
220- image_data += 'Content-Type: %s' % self.get_content_type(value['filename']) + crlf
221- image_data += 'Content-Disposition: form-data; name="%s"; filename="%s"' % (key, value['filename']) + crlf
222- image_data += crlf
223- image_data = image_data.encode('utf-8')
224-
225- body += image_data
226- body += value['content']
227-
228- end_data = crlf + '--' + boundary + '--' + crlf
229- end_data += crlf
230- end_data = end_data.encode('utf-8')
231- body += end_data
232- """
233-
210+
234211 content_type = 'multipart/form-data; boundary=%s' % boundary
235212
236213 return content_type , body
0 commit comments