salesforce-python-sdk
salesforce-python-sdk copied to clipboard
login.py: SOAP XML response with British pound symbol causes encoding error
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.
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)
I forked the repo and created a pull request from my branch into this master: #9