MCPcopy
hub / github.com/httpie/cli / http

Function http

tests/utils/__init__.py:326–455  ·  view source on GitHub ↗

Run HTTPie and capture stderr/out and exit status. Content written to devnull will be captured only if env.devnull is set manually. Invoke `httpie.core.main()` with `args` and `kwargs`, and return a `CLIResponse` subclass instance. The return value is either a `StrCLIRespo

(
    *args,
    program_name='http',
    tolerate_error_exit_status=False,
    **kwargs,
)

Source from the content-addressed store, hash-verified

324
325
326def http(
327 *args,
328 program_name='http',
329 tolerate_error_exit_status=False,
330 **kwargs,
331) -> Union[StrCLIResponse, BytesCLIResponse]:
332 # noinspection PyUnresolvedReferences
333 """
334 Run HTTPie and capture stderr/out and exit status.
335 Content written to devnull will be captured only if
336 env.devnull is set manually.
337
338 Invoke `httpie.core.main()` with `args` and `kwargs`,
339 and return a `CLIResponse` subclass instance.
340
341 The return value is either a `StrCLIResponse`, or `BytesCLIResponse`
342 if unable to decode the output. Devnull is string when possible,
343 bytes otherwise.
344
345 The response has the following attributes:
346
347 `stdout` is represented by the instance itself (print r)
348 `stderr`: text written to stderr
349 `devnull` text written to devnull.
350 `exit_status`: the exit status
351 `json`: decoded JSON (if possible) or `None`
352
353 Exceptions are propagated.
354
355 If you pass ``tolerate_error_exit_status=True``, then error exit statuses
356 won't result into an exception.
357
358 Example:
359
360 $ http --auth=user:password GET pie.dev/basic-auth/user/password
361
362 >>> httpbin = getfixture('httpbin')
363 >>> r = http('-a', 'user:pw', httpbin + '/basic-auth/user/pw')
364 >>> type(r) == StrCLIResponse
365 True
366 >>> r.exit_status is ExitStatus.SUCCESS
367 True
368 >>> r.stderr
369 ''
370 >>> 'HTTP/1.1 200 OK' in r
371 True
372 >>> r.json == {'authenticated': True, 'user': 'user'}
373 True
374
375 """
376 env = kwargs.get('env')
377 if not env:
378 env = kwargs['env'] = MockEnvironment()
379
380 stdout = env.stdout
381 stderr = env.stderr
382 devnull = env.devnull
383

Calls 8

MockEnvironmentClass · 0.85
dump_stderrFunction · 0.85
ExitStatusErrorClass · 0.85
getMethod · 0.80
decodeMethod · 0.80
from_raw_dataMethod · 0.80
writeMethod · 0.45
cleanupMethod · 0.45