How to use the httpx.Client function in httpx

To help you get started, weā€™ve selected a few httpx 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 nsidnev / fastapi-realworld-example-app / tests / test_api / test_errors / test_422_error.py View on Github external
async def test_frw_validation_error_format(app: FastAPI):
    @app.get("/wrong_path/{param}")
    def route_for_test(param: int) -> None:  # pragma: no cover
        pass

    client = Client(base_url="http://testserver", app=app)
    response = await client.get("/wrong_path/asd")
    assert response.status_code == HTTP_422_UNPROCESSABLE_ENTITY

    error_data = response.json()
    assert "errors" in error_data
github encode / httpx / tests / dispatch / test_threaded.py View on Github external
def test_threaded_streaming_request():
    url = "https://example.org/echo_request_body"
    with Client(dispatch=MockDispatch()) as client:
        response = client.post(url, data=streaming_body())

    assert response.status_code == 200
    assert response.text == "Hello, world!"
github encode / httpx / tests / dispatch / test_threaded.py View on Github external
def test_threaded_request_body():
    url = "https://example.org/echo_request_body"
    with Client(dispatch=MockDispatch()) as client:
        response = client.post(url, data=b"Hello, world!")

    assert response.status_code == 200
    assert response.text == "Hello, world!"
github encode / httpx / tests / dispatch / test_http2.py View on Github external
async def test_http2_live_request():
    async with Client(http2=True) as client:
        try:
            resp = await client.get("https://nghttp2.org/httpbin/anything")
        except TimeoutException:
            pytest.xfail(reason="nghttp2.org appears to be unresponsive")
        except socket.gaierror:
            pytest.xfail(reason="You appear to be offline")
        assert resp.status_code == 200
        assert resp.http_version == "HTTP/2"
github encode / httpx / tests / client / test_redirects.py View on Github external
async def test_redirect_302():
    client = Client(dispatch=MockDispatch())
    response = await client.post("https://example.org/redirect_302")
    assert response.status_code == codes.OK
    assert response.url == URL("https://example.org/")
    assert len(response.history) == 1
github encode / httpx / tests / client / test_properties.py View on Github external
def test_client_cookies():
    client = Client()
    client.cookies = {"a": "b"}
    assert isinstance(client.cookies, Cookies)
    mycookies = list(client.cookies.jar)
    assert len(mycookies) == 1
    assert mycookies[0].name == "a" and mycookies[0].value == "b"
github encode / httpx / tests / client / test_async_client.py View on Github external
async def test_uds(uds_server):
    url = uds_server.url
    uds = uds_server.config.uds
    assert uds is not None
    async with httpx.Client(uds=uds) as client:
        response = await client.get(url)
    assert response.status_code == 200
    assert response.text == "Hello, world!"
    assert response.encoding == "iso-8859-1"
github huge-success / sanic / sanic / testing.py View on Github external
def get_new_session(self):
        return httpx.Client()
github encode / httpx / tests / test_wsgi.py View on Github external
def test_wsgi_exc():
    client = httpx.Client(app=raise_exc)
    with pytest.raises(ValueError):
        client.get("http://www.example.org/")
github biolab / orange3-imageanalytics / orangecontrib / imageanalytics / server_embedder.py View on Github external
by either getting a successful response from the server,
            getting the result from cache or skipping the image.

        Returns
        -------
        embeddings
            Array-like of float arrays (embeddings) for successfully embedded
            images and Nones for skipped images.

        Raises
        ------
        EmbeddingCancelledException:
            If cancelled attribute is set to True (default=False).
        """
        requests = []
        async with httpx.Client(
                timeout=self.timeouts, base_url=self.server_url) as client:
            for p in file_paths:
                if self.cancelled:
                    raise EmbeddingCancelledException()
                requests.append(
                    self._send_to_server(
                        p, n_repeats, client, proc_callback))

            embeddings = await asyncio.gather(*requests)
        self._cache.persist_cache()
        assert self.num_parallel_requests == 0

        return embeddings