class PardotAPIError(Exception):
    """
    Basic exception class for errors encountered in API post and get requests. Takes the json response and parses out
    the error code and message.
    """

    def __init__(self, json_response):
        self.response = json_response
        try:
            self.err_code = json_response['@attributes']['err_code']
            self.message = str(json_response['err'])
        except KeyError:
            self.err_code = 0
            self.message = 'Unknown API error occurred'

    def __str__(self):
        return 'Pardot API Error {err_code}: {message}'.format(err_code=self.err_code, message=self.message)

@@ -274,25 +274,8 @@
 nse%0A
-        try:%0A    
     
@@ -307,17 +307,21 @@
 response
-%5B
+.get(
 '@attrib
@@ -329,10 +329,14 @@
 tes'
-%5D%5B
+).get(
 'err
@@ -345,14 +345,10 @@
 ode'
-%5D%0A    
+)%0A
     
@@ -387,15 +387,19 @@
 onse
-%5B
+.get(
 'err'
-%5D
+)
 )%0A  
@@ -408,23 +408,32 @@
     
-except KeyError
+if self.err_code is None
 :%0A  

Refactor error data extraction from JSON