salesforce-python-sdk icon indicating copy to clipboard operation
salesforce-python-sdk copied to clipboard

login.py: SOAP XML response with British pound symbol causes encoding error

Open dalefrancum opened this issue 9 years ago • 2 comments

While using British pounds for currency, during the SOAP API call to authenticate, a response is returned from Salesforce which contains this line:

<currencySymbol>£</currencySymbol>

The login.py code tried to parse the response with this line:

xml_value = xml.dom.minidom.parseString(response.text)

The following error occurred:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 777: ordinal not in range(128)

I have a proposed fix for this, which is to remove the <currencySymbol> node from the XML response string. I will post the patch shortly.

dalefrancum avatar Dec 29 '16 17:12 dalefrancum

I don't have rights to push a branch. Here is a diff for my code changes:

--- a/salesforce/login.py
+++ b/salesforce/login.py
@@ -3,6 +3,7 @@ from exception import AuthenticationFailed
 import urllib
 import utils
 import xml.dom.minidom
+import re


 class Authentication(object):
@@ -165,7 +166,10 @@ class LoginWithSoapAPI(Login):
                                       headers,
                                       data=data)

-        xml_value = xml.dom.minidom.parseString(response.text)
+        # Remove currency symbol from XML response
+        response_text  = re.sub('<currencySymbol>.*</currencySymbol>', '', response.text)
+
+        xml_value = xml.dom.minidom.parseString(response_text)
         access_token = utils.get_element_by_name(xml_value, 'sessionId')
         url = urlparse(utils.get_element_by_name(xml_value, 'serverUrl'))
         instance_url = '{0}://{1}'.format(url.scheme, url.netloc)

dalefrancum avatar Dec 29 '16 17:12 dalefrancum

I forked the repo and created a pull request from my branch into this master: #9

dalefrancum avatar Jan 10 '17 20:01 dalefrancum