def _call(self, resource, arguments, method='GET'):
        try:
            _logger.debug("Start calling Shopware api %s", method)
            client = shopwarelib.sapi()
            client.setCredentials(self.shopware.username, self.shopware.token,
                                  self.shopware.location)
            result = client.call(resource, method, arguments, arguments)

            if type(result) is type(bool) and result is False:
                raise NetworkRetryableError(
                    'Shopware API could not be reached.')

            return result
        except (socket.gaierror, socket.error, socket.timeout) as err:
            raise NetworkRetryableError(
                'A network error caused the failure of the job: '
                '%s' % err)
        except xmlrpclib.ProtocolError as err:
            if err.errcode in [
                    502,  # Bad gateway
                    503,  # Service unavailable
                    504
            ]:  # Gateway timeout
                raise RetryableJobError(
                    'A protocol error caused the failure of the job:\n'
                    'URL: %s\n'
                    'HTTP/HTTPS headers: %s\n'
                    'Error code: %d\n'
                    'Error message: %s\n' %
                    (err.url, err.headers, err.errcode, err.errmsg))
            else:
                raise
 def write(self, model, id, data):
     """ Update records on the external system """
     try:
         start = datetime.now()
         try:
             result = self.server.write(self.uid, self.password, model, id,
                                        data)
         except:
             _logger.error("write(%s, %s, %s) failed", model, id, data)
             raise
         else:
             _logger.debug("write(%s, %s, %s) returned %s in %s seconds",
                           model, id, data, result,
                           (datetime.now() - start).seconds)
         return result
     except (socket.gaierror, socket.error, socket.timeout) as err:
         raise NetworkRetryableError(
             'A network error caused the failure of the job: '
             '%s' % err)
     except xmlrpclib.ProtocolError as err:
         if err.errcode in [502,   # Bad gateway
                            503,   # Service unavailable
                            504]:  # Gateway timeout
             raise RetryableJobError(
                 'A protocol error caused the failure of the job:\n'
                 'URL: %s\n'
                 'HTTP/HTTPS headers: %s\n'
                 'Error code: %d\n'
                 'Error message: %s\n' %
                 (err.url, err.headers, err.errcode, err.errmsg))
         else:
             raise
Exemple #3
0
 def _call(self, method, arguments):
     try:
         custom_url = self.magento.use_custom_api_path
         with magentolib.API(self.magento.location,
                             self.magento.username,
                             self.magento.password,
                             full_url=custom_url) as api:
             result = api.call(method, arguments)
             # Uncomment to record requests/responses in ``recorder``
             # record(method, arguments, result)
             _logger.debug("api.call(%s, %s) returned %s", method,
                           arguments, result)
             return result
     except (socket.gaierror, socket.error, socket.timeout) as err:
         raise NetworkRetryableError(
             'A network error caused the failure of the job: '
             '%s' % err)
     except xmlrpclib.ProtocolError as err:
         if err.errcode in [
                 502,  # Bad gateway
                 503,  # Service unavailable
                 504
         ]:  # Gateway timeout
             raise RetryableJobError(
                 'A protocol error caused the failure of the job:\n'
                 'URL: %s\n'
                 'HTTP/HTTPS headers: %s\n'
                 'Error code: %d\n'
                 'Error message: %s\n' %
                 (err.url, err.headers, err.errcode, err.errmsg))
         else:
             raise
Exemple #4
0
 def _call(self, method, arguments):
     try:
         api = Client(
             location=self.highjump.location + '/pubfun/warehouse.asmx',
             url=self.highjump.location + '/pubfun/warehouse.asmx?WSDL')
         result = getattr(api.service, method)(**arguments)
         _logger.debug("api.call(%s, %s) returned %s", method, arguments,
                       result)
         return result
     except (socket.gaierror, socket.error, socket.timeout) as err:
         raise NetworkRetryableError(
             'A network error caused the failure of the job: '
             '%s' % err)
 def _call(self, method, arguments):
     try:
         _logger.debug("Start calling Woocommerce api %s", method)
         api = API(url=self.woo.location,
                   consumer_key=self.woo.consumer_key,
                   consumer_secret=self.woo.consumer_secret,
                   version='v2')
         if api:
             if isinstance(arguments, list):
                 while arguments and arguments[-1] is None:
                     arguments.pop()
             start = datetime.now()
             try:
                 if 'false' or 'true' or 'null' in api.get(method).content:
                     result = api.get(method).content.replace(
                         'false', 'False')
                     result = result.replace('true', 'True')
                     result = result.replace('null', 'False')
                     result = eval(result)
                 else:
                     result = eval(api.get(method).content)
             except:
                 _logger.error("api.call(%s, %s) failed", method, arguments)
                 raise
             else:
                 _logger.debug("api.call(%s, %s) returned %s in %s seconds",
                               method, arguments, result,
                               (datetime.now() - start).seconds)
             return result
     except (socket.gaierror, socket.error, socket.timeout) as err:
         raise NetworkRetryableError(
             'A network error caused the failure of the job: '
             '%s' % err)
     except xmlrpclib.ProtocolError as err:
         if err.errcode in [
                 502,  # Bad gateway
                 503,  # Service unavailable
                 504
         ]:  # Gateway timeout
             raise RetryableJobError(
                 'A protocol error caused the failure of the job:\n'
                 'URL: %s\n'
                 'HTTP/HTTPS headers: %s\n'
                 'Error code: %d\n'
                 'Error message: %s\n' %
                 (err.url, err.headers, err.errcode, err.errmsg))
         else:
             raise
 def _call(self, method, arguments):
     try:
         custom_url = self.magento.use_custom_api_path
         _logger.debug("Start calling Magento api %s", method)
         with magentolib.API(self.magento.location,
                             self.magento.username,
                             self.magento.password,
                             full_url=custom_url) as api:
             # When Magento is installed on PHP 5.4+, the API
             # may return garble data if the arguments contain
             # trailing None.
             if isinstance(arguments, list):
                 while arguments and arguments[-1] is None:
                     arguments.pop()
             start = datetime.now()
             try:
                 result = api.call(method, arguments)
             except:
                 _logger.error("api.call(%s, %s) failed", method, arguments)
                 raise
             else:
                 _logger.debug("api.call(%s, %s) returned %s in %s seconds",
                               method, arguments, result,
                               (datetime.now() - start).seconds)
             # Uncomment to record requests/responses in ``recorder``
             # record(method, arguments, result)
             return result
     except (socket.gaierror, socket.error, socket.timeout) as err:
         raise NetworkRetryableError(
             'A network error caused the failure of the job: '
             '%s' % err)
     except xmlrpclib.ProtocolError as err:
         if err.errcode in [
                 502,  # Bad gateway
                 503,  # Service unavailable
                 504
         ]:  # Gateway timeout
             raise RetryableJobError(
                 'A protocol error caused the failure of the job:\n'
                 'URL: %s\n'
                 'HTTP/HTTPS headers: %s\n'
                 'Error code: %d\n'
                 'Error message: %s\n' %
                 (err.url, err.headers, err.errcode, err.errmsg))
         else:
             raise