Identify and close specific connection in AsyncClient
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
@BlackCloud37on 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:
- Close a connection after N requests.
- 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:
- Identify each request's underlying connection, so I can count requests on certain connection.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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