TypeError: 'Timeout' object cannot be interpreted as an integer in sync connect_tcp when a request carries a Timeout object in extensions
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- backend, networking
Research direction
Start in httpcore2/_backends/sync.py at SyncBackend.connect_tcp, then inspect the corresponding timeout handling in connect_unix_socket and start_tls. Reproduce the issue with the offline Request example and verify that a Timeout object is converted to an acceptable connection timeout or produces a clean error rather than a stdlib TypeError.
Written by the indexing model from the issue text.
Description
Summary
httpcore2/_backends/sync.py SyncBackend.connect_tcp passes the request timeout straight into socket.create_connection(address, timeout, ...). When a request's extensions["timeout"]["connect"] carries a Timeout object instead of a float (some SDK request builders do this — we hit it through the anthropic SDK path in hermes-agent), Python raises TypeError: 'Timeout' object cannot be interpreted as an integer before any network I/O, which the caller sees as a bogus APIConnectionError.
Reproducer (offline, no network needed)
import httpx2
from httpx2 import Timeout, Request, Client
r = Request("GET", "http://127.0.0.1:1/")
r.extensions["timeout"] = {"connect": Timeout(5.0)}
Client().send(r)
Result:
TypeError: 'Timeout' object cannot be interpreted as an integer
File ".../httpcore2/_backends/sync.py", line 204, in connect_tcp
sock = socket.create_connection(address, timeout, ...)
File ".../socket.py", line 845, in create_connection
sock.settimeout(timeout)
Environment
- httpcore2 / httpx2 2.7.0
- Python 3.11.13, macOS
Expected
socket.create_connection accepts only float | None. A Timeout object in the extensions should either be coerced (its numeric .connect attribute is the value) or surfaced as a clean error — not a stdlib TypeError from deep inside the connect path.
Suggested fix
In connect_tcp (and the same pattern in connect_unix_socket / start_tls):
if timeout is not None and not isinstance(timeout, (int, float)):
timeout = getattr(timeout, "connect", None)
We applied exactly this as a local patch and it resolves the failure.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 103
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from pydantic/httpx2
-
Please revert aiter_bytes signature to AsyncIteratorMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydantic/httpx2#1158 · 2 comments ·
Maintainers usually reply within 1 day
-
Export AutoBackendMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
pydantic/httpx2#1131 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Mention header name error message for invalid header encodingsMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydantic/httpx2#864 · 3 comments ·
Maintainers usually reply within 1 day
-
Support DigestAuth with "x-www-authenticate" in first response headerPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Email validation accepts a trailing newlinePossibly taken @marcello-pichini claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dbt-labs/spark-utils#51 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug frontend
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
vendrabuck/HERD#1419 ·
Maintainers usually reply within 1 day