-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Replace httpx and httpx-sse with httpx2 #2972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |||||
| from contextlib import AsyncExitStack | ||||||
| from typing import Any | ||||||
|
|
||||||
| import httpx | ||||||
| import httpx2 | ||||||
| from dotenv import load_dotenv | ||||||
| from mcp import ClientSession, StdioServerParameters | ||||||
| from mcp.client.stdio import stdio_client | ||||||
|
|
@@ -230,7 +230,7 @@ def get_response(self, messages: list[dict[str, str]]) -> str: | |||||
| The LLM's response as a string. | ||||||
|
|
||||||
| Raises: | ||||||
| httpx.RequestError: If the request to the LLM fails. | ||||||
| httpx2.RequestError: If the request to the LLM fails. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Docstring states this method raises Prompt for AI agents |
||||||
| """ | ||||||
| url = "https://api.groq.com/openai/v1/chat/completions" | ||||||
|
|
||||||
|
|
@@ -249,17 +249,17 @@ def get_response(self, messages: list[dict[str, str]]) -> str: | |||||
| } | ||||||
|
|
||||||
| try: | ||||||
| with httpx.Client() as client: | ||||||
| with httpx2.Client() as client: | ||||||
| response = client.post(url, headers=headers, json=payload) | ||||||
| response.raise_for_status() | ||||||
| data = response.json() | ||||||
| return data["choices"][0]["message"]["content"] | ||||||
|
|
||||||
| except httpx.RequestError as e: | ||||||
| except httpx2.RequestError as e: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Suggested change
|
||||||
| error_message = f"Error getting LLM response: {str(e)}" | ||||||
| logging.error(error_message) | ||||||
|
|
||||||
| if isinstance(e, httpx.HTTPStatusError): | ||||||
| if isinstance(e, httpx2.HTTPStatusError): | ||||||
| status_code = e.response.status_code | ||||||
| logging.error(f"Status code: {status_code}") | ||||||
| logging.error(f"Response details: {e.response.text}") | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,8 +92,8 @@ | |
| format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | ||
| ) | ||
| # Suppress noisy HTTP client logging | ||
| logging.getLogger("httpx").setLevel(logging.WARNING) | ||
| logging.getLogger("httpx2").setLevel(logging.WARNING) | ||
| logging.getLogger("httpcore").setLevel(logging.WARNING) | ||
|
Check warning on line 96 in examples/clients/sse-polling-client/mcp_sse_polling_client/main.py
|
||
|
Comment on lines
+95
to
96
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 The adjacent line was updated to suppress the Extended reasoning...What the bug is. This PR replaces the Why the existing line no longer does anything. Python library loggers are named after the module path ( Code path / proof. Step through running the example with verbose logging:
Impact. Limited: this is an example client, and httpcore-style logging is DEBUG-level, so nothing changes at the default Fix. One-word change: |
||
|
|
||
| asyncio.run(run_demo(url, items, checkpoint_every)) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,14 +27,13 @@ | |
| dependencies = [ | ||
| # anyio < 4.10 triggers a compile-time SyntaxWarning on Python 3.14 (PEP 765, | ||
| # "'return' in a 'finally' block"); for stdio servers it lands on the child's | ||
| # stderr (agronholm/anyio#816, fixed in 4.10). | ||
| "anyio>=4.10; python_version >= '3.14'", | ||
| "anyio>=4.9; python_version < '3.14'", | ||
| "httpx>=0.27.1,<1.0.0", | ||
| "httpx-sse>=0.4", | ||
| "httpx2>=2.5.0", | ||
| "pydantic>=2.12.0", | ||
| "starlette>=0.48.0; python_version >= '3.14'", | ||
| "starlette>=0.27; python_version < '3.14'", | ||
|
Check failure on line 36 in pyproject.toml
|
||
|
Comment on lines
30
to
36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Making the just-published Extended reasoning...What the change does. The PR replaces Maturity/provenance concern. The lockfile records the upload times of the new packages: The undocumented TLS behaviour change. This is the independently actionable part regardless of how the provenance question resolves. With httpx <1.0, default TLS verification used the Concrete walk-through of how this manifests. Take a user running an MCP client in a corporate environment behind a TLS-intercepting proxy whose root CA is installed in the OS trust store but (deliberately) not in certifi. On v1, Why nothing else in the PR mitigates this. The migration guide explicitly claims "httpx2 is API-compatible with httpx, so usually only the import name changes", which actively tells users there is no behavioural change to look for. The test suite runs entirely against in-process ASGI transports and How to fix. (1) Add a section to |
||
| "python-multipart>=0.0.9", | ||
| "sse-starlette>=3.0.0", | ||
| "pydantic-settings>=2.5.2", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Migration text names the old auth base class (
httpx.Auth) in v2 instructions. Usehttpx2.Authto keep guidance consistent and avoid incorrect imports during migration.Prompt for AI agents