@@ -116,7 +116,7 @@ def force_bytes(value):
116
116
"""
117
117
if IS_PY3 :
118
118
if isinstance (value , str ):
119
- value = value .encode ('utf-8' )
119
+ value = value .encode ('utf-8' , 'backslashreplace' )
120
120
else :
121
121
if isinstance (value , unicode ):
122
122
value = value .encode ('utf-8' )
@@ -245,6 +245,9 @@ def _send_request(self, method, path='', body=None, headers=None, files=None):
245
245
method = method .lower ()
246
246
log_body = body
247
247
248
+ if headers is None :
249
+ headers = {}
250
+
248
251
if log_body is None :
249
252
log_body = ''
250
253
elif not isinstance (log_body , str ):
@@ -260,20 +263,17 @@ def _send_request(self, method, path='', body=None, headers=None, files=None):
260
263
raise SolrError ("Unable to send HTTP method '{0}." .format (method ))
261
264
262
265
try :
263
- # Bytes all the way down.
264
- # Except the ``url``. Requests on Py3 *really* wants that to be a
265
- # string, not bytes.
266
+ # Everything except the body can be Unicode. The body must be
267
+ # encoded to bytes to work properly on Py3.
266
268
bytes_body = body
267
- bytes_headers = {}
268
269
269
270
if bytes_body is not None :
270
271
bytes_body = force_bytes (body )
271
272
272
- if headers is not None :
273
- for k , v in headers .items ():
274
- bytes_headers [force_bytes (k )] = force_bytes (v )
273
+ if not 'content-type' in [key .lower () for key in headers .keys ()]:
274
+ headers ['Content-type' ] = 'application/xml; charset=UTF-8'
275
275
276
- resp = requests_method (url , data = bytes_body , headers = bytes_headers , files = files ,
276
+ resp = requests_method (url , data = bytes_body , headers = headers , files = files ,
277
277
timeout = self .timeout )
278
278
except requests .exceptions .Timeout as err :
279
279
error_message = "Connection to server '%s' timed out: %s"
0 commit comments