Skip to content

Commit a3aff66

Browse files
authored
Switch from httpx to httpx2 for API requests
Updated the import statement and modified the get_eth_price_usd function to use httpx2 instead of httpx.
1 parent ad13a49 commit a3aff66

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

‎web_programming/crypto_price.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# /// script
66
# requires-python = ">=3.10"
77
# dependencies = [
8-
# "httpx",
8+
# "httpx2",
99
# ]
1010
# ///
1111

12-
import httpx
12+
import httpx2
1313

1414
COINGECKO_URL = (
1515
"https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
@@ -18,10 +18,7 @@
1818

1919
def get_eth_price_usd() -> float:
2020
"""Fetch the current ETH price in USD."""
21-
response = httpx.get(COINGECKO_URL, timeout=10)
22-
response.raise_for_status()
23-
data = response.json()
24-
return data["ethereum"]["usd"]
21+
return httpx2.get(COINGECKO_URL, timeout=10).raise_for_status().json()["ethereum"]["usd"]
2522

2623

2724
def eth_to_usd(eth_amount: float) -> float:

0 commit comments

Comments
 (0)