How to use the httpie.ExitStatus function in httpie

To help you get started, we’ve selected a few httpie 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 jakubroztocil / httpie / tests / tests.py View on Github external
def test_ok_response_exits_0(self):
        r = http(
            'GET',
            httpbin('/status/200')
        )
        self.assertIn(OK, r)
        self.assertEqual(r.exit_status, ExitStatus.OK)
github jakubroztocil / httpie / tests / tests.py View on Github external
def test_3xx_check_status_exits_3_and_stderr_when_stdout_redirected(self):
        r = http(
            '--check-status',
            '--headers',  # non-terminal, force headers
            'GET',
            httpbin('/status/301'),
            env=TestEnvironment(stdout_isatty=False,)
        )
        self.assertIn('HTTP/1.1 301', r)
        self.assertEqual(r.exit_status, ExitStatus.ERROR_HTTP_3XX)
        self.assertIn('301 moved permanently', r.stderr.lower())
github jakubroztocil / httpie / tests / tests.py View on Github external
def test_timeout_exit_status(self):
        r = http(
            '--timeout=0.5',
            'GET',
            httpbin('/delay/1')
        )
        self.assertEqual(r.exit_status, ExitStatus.ERROR_TIMEOUT)
github jakubroztocil / httpie / tests / tests.py View on Github external
env = kwargs['env'] = TestEnvironment()

    stdout = env.stdout
    stderr = env.stderr
    try:

        try:
            exit_status = main(args=['--traceback'] + list(args), **kwargs)
            if '--download' in args:
                # Let the progress reporter thread finish.
                time.sleep(.5)
        except Exception:
            sys.stderr.write(stderr.read())
            raise
        except SystemExit:
            exit_status = ExitStatus.ERROR

        stdout.seek(0)
        stderr.seek(0)

        output = stdout.read()
        try:
            r = StrResponse(output.decode('utf8'))
        except UnicodeDecodeError:
            r = BytesResponse(output)
        else:
            if COLOR not in r:
                # De-serialize JSON body if possible.
                if r.strip().startswith('{'):
                    #noinspection PyTypeChecker
                    r.json = json.loads(r)
                elif r.count('Content-Type:') == 1 and 'application/json' in r:
github jakubroztocil / httpie / tests / tests.py View on Github external
def test_4xx_check_status_exits_4(self):
        r = http(
            '--check-status',
            'GET',
            httpbin('/status/401')
        )
        self.assertIn('HTTP/1.1 401', r)
        self.assertEqual(r.exit_status, ExitStatus.ERROR_HTTP_4XX)
        # Also stderr should be empty since stdout isn't redirected.
        self.assertTrue(not r.stderr)
github jakubroztocil / httpie / tests / tests.py View on Github external
def test_5xx_check_status_exits_5(self):
        r = http(
            '--check-status',
            'GET',
            httpbin('/status/500')
        )
        self.assertIn('HTTP/1.1 500', r)
        self.assertEqual(r.exit_status, ExitStatus.ERROR_HTTP_5XX)
github httpie / httpie-aws-auth / httpie_aws_auth.py View on Github external
# There's a differences between None and '': only use the
        # env vars when --auth, -a not specified at all, otherwise
        # the behaviour would be confusing to the user.
        access_key = os.environ.get(KEY) if username is None else username
        secret = os.environ.get(SECRET) if password is None else password
        if not access_key or not secret:
            missing = []
            if not access_key:
                missing.append(KEY)
            if not secret:
                missing.append(SECRET)
            sys.stderr.write(
                'httpie-aws-auth error: missing {1}\n'
                .format(self.name, ' and '.join(missing))
            )
            sys.exit(ExitStatus.PLUGIN_ERROR)

        return BytesHeadersFriendlyS3Auth(access_key, secret)