def _run_put_request_with_retry(self, url, body, headers): retry = 0 response = None while True: gc.collect() try: self._logger.debug("Trying to send...") response = requests.put(url, json=body, headers=headers) self._logger.debug("Sent!") break except RuntimeError as runtime_error: self._logger.info( "Could not send data, retrying after 0.5 seconds: " + str(runtime_error) ) retry = retry + 1 if retry >= 10: self._logger.error("Failed to send data") raise time.sleep(0.5) continue gc.collect() return response
def put(self, url, **kw): """ Pass the put request to requests and update status LED :param str url: The URL to PUT data to :param dict data: (Optional) Form data to submit :param dict json: (Optional) JSON data to submit. (Data must be None) :param dict header: (Optional) Header data to include :param bool stream: (Optional) Whether to stream the Response :return: The response from the request :rtype: Response """ if not self.is_connected: self.connect() self.pixel_status((0, 0, 100)) return_val = requests.put(url, **kw) self.pixel_status(0) return return_val