# -*- coding: utf-8 -*- import httpx def get_public_ip(): try: # 使用 httpx 发起请求 response = httpx.get("https://httpbin.org/ip", timeout=10) response.raise_for_status() # 检查请求是否成功 ip_data = response.json() return ip_data["origin"] except httpx.RequestError as e: print(f"An error occurred while obtaining the public IP address.:{e}") exit(1)