Skip to content

Commit f32c8f1

Browse files
author
sunnyrajrathod
committed
- Fix for issue #65 and #73.
- In apicontrollersbase.py, when an exception occured, another exception was thrown while trying to call CreateFromDocument function. Due to this, the xmlResponse to lxml object conversion did not happen correctly and hence the API errors were not deserialized correctly. - Also, for issue #73, added utf-8 encode and decode methods, so that response can be logged correctly.
1 parent 73eb482 commit f32c8f1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Diff for: authorizenet/apicontrollersbase.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,20 @@ def execute(self):
147147

148148
except Exception as objectifyexception:
149149
logging.error( 'Create Document Exception: %s, %s', type(objectifyexception), objectifyexception.args )
150-
pyxb.GlobalValidationConfig._setForBinding(False)
151-
self._response = apicontractsv1.CreateFromDocument(self._httpResponse)
152-
#objectify code
153-
xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
154-
xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'')
155-
xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'')
156-
self._mainObject = objectify.fromstring(xmlResponse)
157-
else:
150+
responseString = self._httpResponse
151+
152+
# removing encoding attribute as objectify fails if it is present
153+
responseString = responseString.replace('encoding=\"utf-8\"', '')
154+
self._mainObject = objectify.fromstring(responseString)
155+
else:
156+
domResponse = xml.dom.minidom.parseString(self._httpResponse)
157+
158158
#if type(self.getresponseclass()) == type(self._response):
159159
if type(self.getresponseclass()) != type(self._mainObject):
160160
if self._response.messages.resultCode == "Error":
161161
logging.debug("Response error")
162-
domResponse = xml.dom.minidom.parseString(self._httpResponse)
163-
logging.debug('Received response: %s' % domResponse.toprettyxml())
162+
domResponse = xml.dom.minidom.parseString(self._httpResponse.encode('utf-8').decode('utf-8'))
163+
logging.debug('Received response: %s' % domResponse.toprettyxml(encoding='utf-8'))
164164
else:
165165
#Need to handle ErrorResponse
166166
logging.debug('Error retrieving response for request: %s' % self._request)

Diff for: tests/testpyxb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def testGetCustomerProfile(self):
171171

172172
logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
173173

174-
self.assertEquals(type(getCustomerProfileRequest), type(deserializedObject), "deseriaziedObject does not match original object")
174+
self.assertEqual(type(getCustomerProfileRequest), type(deserializedObject), "deseriaziedObject does not match original object")
175175

176176
try:
177177
#print("starting with element in mid")

0 commit comments

Comments
 (0)