File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525
2626from ebaysdk .utils import xml2dict , dict2xml , list2xml , object_dict
2727
28+ content_type_re = re .compile ('^Content\-Type:\s([^;]+);charset=(.*?)$' , re .I )
2829
2930def get_version ():
3031 "Get the version."
@@ -357,6 +358,24 @@ def _process_http_request(self):
357358 self ._response_reason = re .match (r'^HTTP.+? +\d+ +(.*) *$' , self ._response_status ).group (1 )
358359 response_data = self ._response_body .getvalue ()
359360
361+ # Look for charset specifier and decode the response_data
362+ # based on it.
363+ for header in self ._response_header .getvalue ().splitlines ():
364+ header_match = content_type_re .match (header )
365+
366+ try :
367+ if header_match and header_match .group (2 ):
368+ response_data = response_data .decode (header_match .group (2 ))
369+ break
370+ except Exception as e :
371+ charset = ''
372+ try :
373+ charset = header_match .group (2 )
374+ except Exception :
375+ pass
376+
377+ sys .stderr .write ("Failed to decode response using charset %s (%s)\n " % (charset , str (e )))
378+
360379 self ._response_header = None
361380 self ._response_body = None
362381 self ._curl .close ()
You can’t perform that action at this time.
0 commit comments