pydantic / pydantic/httpx2

Identify and close specific connection in AsyncClient

Open
#910 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
76
Avg merge
8h 59m
Merged PRs (30d)
24

Description

Originally opened by @BlackCloud37 on 2025-08-25 06:04:51 in encode/httpx

Hello,

I'm trying to use httpx(in asyncio) for my web scraper program.

In my use case, to prevent my connection from banning, I usually want to limit the request on single connection, which means:

  1. Close a connection after N requests.
  2. If a connection is banned, for example, received HTTP code 429 or any invalid response.

By reading the document, I cannot find any methods that I can:

  1. Identify each request's underlying connection, so I can count requests on certain connection.
  2. To close this single connection if satisfied any condition above.

So I currently implement this in "one connection per async client" way. I limited the max_connections to 1 for my client, and each time I want to drop a connection, I throw the client away and create a new one.

As the document says, it's a bad idea to do so. So is there any way I can reuse the clients for my purpose?

Any help would be much appreciated!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or code entry points. Start by reviewing AsyncClient's documented connection controls and the current connection-pool behavior; a completed investigation should establish whether per-connection identification and selective closure are supported or require a scoped design.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.