def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response.dom() if dom is None: return errors for e in dom.findall("error"): eSeverity = None eDomain = None eMsg = None eId = None try: eSeverity = e.findall('severity')[0].text except IndexError: pass try: eDomain = e.findall('domain')[0].text except IndexError: pass try: eId = e.findall('errorId')[0].text if int(eId) not in resp_codes: resp_codes.append(int(eId)) except IndexError: pass try: eMsg = e.findall('message')[0].text except IndexError: pass msg = "Domain: %s, Severity: %s, errorId: %s, %s" \ % (eDomain, eSeverity, eId, eMsg) if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) try: if self.response.reply.ack == 'Success' and len( errors) > 0 and self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) elif len(errors) > 0: if self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) return errors except AttributeError as e: return errors return []
def error_check(self): estr = self.error() if estr and self.config.get('errors', True): log.error(estr) raise ConnectionError(estr, self.response)
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response_dom() if dom is None: return errors for e in dom.getElementsByTagName("error"): eSeverity = None eDomain = None eMsg = None eId = None if e.getElementsByTagName('severity'): eSeverity = getNodeText(e.getElementsByTagName('severity')[0]) if e.getElementsByTagName('domain'): eDomain = getNodeText(e.getElementsByTagName('domain')[0]) if e.getElementsByTagName('errorId'): eId = getNodeText(e.getElementsByTagName('errorId')[0]) if int(eId) not in resp_codes: resp_codes.append(int(eId)) if e.getElementsByTagName('message'): eMsg = getNodeText(e.getElementsByTagName('message')[0]) msg = "Domain: %s, Severity: %s, errorId: %s, %s" \ % (eDomain, eSeverity, eId, eMsg) if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) try: if self.response_dict().ack == 'Success' and len(errors) > 0 and self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) elif len(errors) > 0: if self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) return errors except AttributeError: pass return []
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response.dom() if dom is None: return errors for e in dom.findall('Errors'): eSeverity = None eClass = None eShortMsg = None eLongMsg = None eCode = None try: eSeverity = e.findall('SeverityCode')[0].text except IndexError: pass try: eClass = e.findall('ErrorClassification')[0].text except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text except IndexError: pass try: eShortMsg = smart_encode(e.findall('ShortMessage')[0].text) except IndexError: pass try: eLongMsg = smart_encode(e.findall('LongMessage')[0].text) except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text if int(eCode) not in resp_codes: resp_codes.append(int(eCode)) except IndexError: pass msg = str("Class: {eClass}, Severity: {severity}, Code: {code}, {shortMsg} {longMsg}") \ .format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=eShortMsg, longMsg=eLongMsg) # from IPython import embed; embed() if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("{verb}: {message}\n\n".format( verb=self.verb, message="\n".join(warnings))) if self.response.reply.Ack == 'Failure': if self.config.get('errors'): log.error("{verb}: {message}\n\n".format( verb=self.verb, message="\n".join(errors))) return errors return []
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response.dom() if dom is None: return errors for e in dom.findall('Errors'): eSeverity = None eClass = None eShortMsg = None eLongMsg = None eCode = None try: eSeverity = e.findall('SeverityCode')[0].text except IndexError: pass try: eClass = e.findall('ErrorClassification')[0].text except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text except IndexError: pass try: eShortMsg = e.findall('ShortMessage')[0].text except IndexError: pass try: eLongMsg = e.findall('LongMessage')[0].text except IndexError: pass try: eCode = float(e.findall('ErrorCode')[0].text) if eCode.is_integer(): eCode = int(eCode) if eCode not in resp_codes: resp_codes.append(eCode) except IndexError: pass msg = "Class: %s, Severity: %s, Code: %s, %s%s" \ % (eClass, eSeverity, eCode, eShortMsg, eLongMsg) if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) if self.response.reply.Ack == 'Failure': if self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) return errors return []
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() <errorMessage xmlns="http://www.ebay.com/marketplace/search/v1/services"><error><errorId>5014</errorId><domain>CoreRuntime</domain><severity>Error</severity><category>System</category><message> """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response.dom() if dom is None: return errors for e in dom.findall('error'): eSeverity = None eDomain = None eMsg = None eId = None try: eSeverity = e.findall('severity')[0].text except IndexError: pass try: eDomain = e.findall('domain')[0].text except IndexError: pass try: eId = e.findall('errorId')[0].text if int(eId) not in resp_codes: resp_codes.append(int(eId)) except IndexError: pass try: eMsg = e.findall('message')[0].text except IndexError: pass msg = "Domain: %s, Severity: %s, errorId: %s, %s" \ % (eDomain, eSeverity, eId, eMsg) if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) try: if self.response.reply.ack == 'Success' and len(errors) > 0 and self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) elif len(errors) > 0: if self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) return errors except AttributeError: pass return []
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response.dom() if dom is None: return errors for e in dom.findall('Errors'): eSeverity = None eClass = None eShortMsg = None eLongMsg = None eCode = None try: eSeverity = e.findall('SeverityCode')[0].text except IndexError: pass try: eClass = e.findall('ErrorClassification')[0].text except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text except IndexError: pass try: eShortMsg = smart_encode(e.findall('ShortMessage')[0].text) except IndexError: pass try: eLongMsg = smart_encode(e.findall('LongMessage')[0].text) except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text if int(eCode) not in resp_codes: resp_codes.append(int(eCode)) except IndexError: pass msg = str("Class: {eClass}, Severity: {severity}, Code: {code}, {shortMsg} {longMsg}") \ .format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=eShortMsg, longMsg=eLongMsg) #from IPython import embed; embed() if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("{verb}: {message}\n\n".format(verb=self.verb, message="\n".join(warnings))) if self.response.reply.Ack == 'Failure': if self.config.get('errors'): log.error("{verb}: {message}\n\n".format(verb=self.verb, message="\n".join(errors))) return errors return []
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response.dom() if dom is None: return errors # In special case we get errors in this format... if not dom.findall('Errors') and dom.find('Body') is not None: dom = dom.find('Body').find('Response') if dom is None: return errors for e in dom.findall('Errors'): eSeverity = None eClass = None eShortMsg = None eLongMsg = None eCode = None try: eSeverity = e.findall('SeverityCode')[0].text except IndexError: pass try: eClass = e.findall('ErrorClassification')[0].text except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text except IndexError: pass try: eShortMsg = e.findall('ShortMessage')[0].text except IndexError: pass try: eLongMsg = e.findall('LongMessage')[0].text except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text try: int_code = int(eCode) except ValueError: int_code = None if int_code and int_code not in resp_codes: resp_codes.append(int_code) except IndexError: pass msg = "Class: {eClass}, Severity: {severity}, Code: {code}, {shortMsg} {longMsg}" \ .format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=smart_encode(eShortMsg), longMsg=smart_encode(eLongMsg)) if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("{verb}: {message}\n\n".format( verb=self.verb, message="\n".join(warnings))) # In special case of error 500 on ebay side, we get really weird response so I need to fallback to this one Ack = getattr(self.response.reply, 'Ack', None) if Ack is None: Ack = self.response.reply.Envelope.Body.Response.Ack if Ack == 'Failure': if self.config.get('errors'): log.error("{verb}: {message}\n\n".format( verb=self.verb, message="\n".join(errors))) return errors return []
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() <errorMessage xmlns="http://www.ebay.com/marketplace/search/v1/services"><error><errorId>5014</errorId><domain>CoreRuntime</domain><severity>Error</severity><category>System</category><message> """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response_dom() if dom is None: return errors for e in dom.getElementsByTagName("error"): eSeverity = None eDomain = None eMsg = None eId = None if e.getElementsByTagName('severity'): eSeverity = getNodeText(e.getElementsByTagName('severity')[0]) if e.getElementsByTagName('domain'): eDomain = getNodeText(e.getElementsByTagName('domain')[0]) if e.getElementsByTagName('errorId'): eId = getNodeText(e.getElementsByTagName('errorId')[0]) if int(eId) not in resp_codes: resp_codes.append(int(eId)) if e.getElementsByTagName('message'): eMsg = getNodeText(e.getElementsByTagName('message')[0]) msg = "Domain: %s, Severity: %s, errorId: %s, %s" \ % (eDomain, eSeverity, eId, eMsg) if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) try: if self.response_dict().ack == 'Success' and len( errors) > 0 and self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) elif len(errors) > 0: if self.config.get('errors'): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) return errors except AttributeError: pass return []
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response.dom() if dom is None: return errors # In special case we get errors in this format... if not dom.findall('Errors') and dom.find('Body') is not None: dom = dom.find('Body').find('Response') if dom is None: return errors for e in dom.findall('Errors'): eSeverity = None eClass = None eShortMsg = None eLongMsg = None eCode = None try: eSeverity = e.findall('SeverityCode')[0].text except IndexError: pass try: eClass = e.findall('ErrorClassification')[0].text except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text except IndexError: pass try: eShortMsg = e.findall('ShortMessage')[0].text except IndexError: pass try: eLongMsg = e.findall('LongMessage')[0].text except IndexError: pass try: eCode = e.findall('ErrorCode')[0].text try: int_code = int(eCode) except ValueError: int_code = None if int_code and int_code not in resp_codes: resp_codes.append(int_code) except IndexError: pass msg = "Class: {eClass}, Severity: {severity}, Code: {code}, {shortMsg} {longMsg}" \ .format(eClass=eClass, severity=eSeverity, code=eCode, shortMsg=smart_encode(eShortMsg), longMsg=smart_encode(eLongMsg)) if eSeverity == 'Warning': warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get('warnings') and len(warnings) > 0: log.warn("{verb}: {message}\n\n".format(verb=self.verb, message="\n".join(warnings))) # In special case of error 500 on ebay side, we get really weird response so I need to fallback to this one Ack = getattr(self.response.reply, 'Ack', None) if Ack is None: Ack = self.response.reply.Envelope.Body.Response.Ack if Ack == 'Failure': if self.config.get('errors'): log.error("{verb}: {message}\n\n".format(verb=self.verb, message="\n".join(errors))) return errors return []
def _get_resp_body_errors(self): """Parses the response content to pull errors. Child classes should override this method based on what the errors in the XML response body look like. They can choose to look at the 'ack', 'Errors', 'errorMessage' or whatever other fields the service returns. the implementation below is the original code that was part of error() """ if self._resp_body_errors and len(self._resp_body_errors) > 0: return self._resp_body_errors errors = [] warnings = [] resp_codes = [] if self.verb is None: return errors dom = self.response.dom() if dom is None: return errors for e in dom.findall("error"): eSeverity = None eDomain = None eMsg = None eId = None try: eSeverity = e.findall("severity")[0].text except IndexError: pass try: eDomain = e.findall("domain")[0].text except IndexError: pass try: eId = e.findall("errorId")[0].text if int(eId) not in resp_codes: resp_codes.append(int(eId)) except IndexError: pass try: eMsg = e.findall("message")[0].text except IndexError: pass msg = "Domain: %s, Severity: %s, errorId: %s, %s" % (eDomain, eSeverity, eId, eMsg) if eSeverity == "Warning": warnings.append(msg) else: errors.append(msg) self._resp_body_warnings = warnings self._resp_body_errors = errors self._resp_codes = resp_codes if self.config.get("warnings") and len(warnings) > 0: log.warn("%s: %s\n\n" % (self.verb, "\n".join(warnings))) try: if self.response.reply.ack == "Success" and len(errors) > 0 and self.config.get("errors"): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) elif len(errors) > 0: if self.config.get("errors"): log.error("%s: %s\n\n" % (self.verb, "\n".join(errors))) return errors except AttributeError as e: return errors return []
def error_check(self): estr = self.error() if estr and self.config.get('errors', True): log.error(estr)