How to use the asciinema.api.APIError function in asciinema

To help you get started, we’ve selected a few asciinema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asciinema / asciinema / asciinema / api.py View on Github external
401: "Invalid or revoked install ID",
            404: "API endpoint not found. This asciinema version may no longer be supported. Please upgrade to the latest version.",
            413: "Sorry, your asciicast is too big.",
            422: "Invalid asciicast: %s" % body,
            503: "The server is down for maintenance. Try again in a minute."
        }

        error = errors.get(status)

        if not error:
            if status >= 500:
                error = "The server is having temporary problems. Try again in a minute."
            else:
                error = "HTTP status: %i" % status

        raise APIError(error)
github asciinema / asciinema / asciinema / commands / upload.py View on Github external
def execute(self):
        try:
            result, warn = self.api.upload_asciicast(self.filename)

            if warn:
                self.print_warning(warn)

            self.print(result.get('message') or result['url'])

        except OSError as e:
            self.print_error("upload failed: %s" % str(e))
            return 1

        except APIError as e:
            self.print_error("upload failed: %s" % str(e))
            self.print_error("retry later by running: asciinema upload %s" % self.filename)
            return 1

        return 0
github timhsutw / honeyterm / honeyterm_asciinema / asciinema / asciinema / commands / record.py View on Github external
if upload:
            if not self.assume_yes:
                self.print_info("Press  to upload,  to cancel.")
                try:
                    sys.stdin.readline()
                except KeyboardInterrupt:
                    return 0

            try:
                url, warn = self.api.upload_asciicast(self.filename)
                if warn:
                    self.print_warning(warn)
                os.remove(self.filename)
                self.print(url)
            except APIError as e:
                self.print_warning("Upload failed: %s" % str(e))
                self.print_warning("Retry later by running: asciinema upload %s" % self.filename)
                return 1

        return 0
github timhsutw / honeyterm / honeyterm_asciinema / asciinema / asciinema / commands / upload.py View on Github external
def execute(self):
        try:
            url, warn = self.api.upload_asciicast(self.filename)

            if warn:
                self.print_warning(warn)

            self.print(url)

        except FileNotFoundError as e:
            self.print_warning("Upload failed: %s" % str(e))
            return 1

        except APIError as e:
            self.print_warning("Upload failed: %s" % str(e))
            self.print_warning("Retry later by running: asciinema upload %s" % self.filename)
            return 1

        return 0
github asciinema / asciinema / asciinema / commands / record.py View on Github external
sys.stdin.readline()
                except KeyboardInterrupt:
                    self.print("\r", end="")
                    self.print_info("asciicast saved to %s" % self.filename)
                    return 0

            try:
                result, warn = self.api.upload_asciicast(self.filename)

                if warn:
                    self.print_warning(warn)

                os.remove(self.filename)
                self.print(result.get('message') or result['url'])

            except APIError as e:
                self.print("\r\x1b[A", end="")
                self.print_error("upload failed: %s" % str(e))
                self.print_error("retry later by running: asciinema upload %s" % self.filename)
                return 1
        else:
            self.print_info("asciicast saved to %s" % self.filename)

        return 0
github asciinema / asciinema / asciinema / api.py View on Github external
def upload_asciicast(self, path):
        with open(path, 'rb') as f:
            try:
                status, headers, body = self.http_adapter.post(
                    self.upload_url(),
                    files={"asciicast": ("ascii.cast", f)},
                    headers=self._headers(),
                    username=self.user,
                    password=self.install_id
                )
            except HTTPConnectionError as e:
                raise APIError(str(e))

        if status != 200 and status != 201:
            self._handle_error(status, body)

        if (headers.get('content-type') or '')[0:16] == 'application/json':
            result = json.loads(body)
        else:
            result = {'url': body}

        return result, headers.get('Warning')