+ # Handle query as multipart when sending media
+ if media:
+ BOUNDARY = "###Python-Twitter###"
+ bod = []
+ bod.append('--' + BOUNDARY)
+ bod.append(
+ 'Content-Disposition: form-data; name="%s"' % mediafield)
+ bod.append('Content-Transfer-Encoding: base64')
+ bod.append('')
+ bod.append(media)
+ for k, v in kwargs.items():
+ bod.append('--' + BOUNDARY)
+ bod.append('Content-Disposition: form-data; name="%s"' % k)
+ bod.append('')
+ bod.append(v)
+ bod.append('--' + BOUNDARY + '--')
+ body = '\r\n'.join(bod)
+ headers['Content-Type'] = \
+ 'multipart/form-data; boundary=%s' % BOUNDARY
+