fork download
  1. import requests
  2.  
  3. def get_public_ip():
  4. """
  5. Retrieves the public IP address using an external API.
  6. """
  7. try:
  8. response = requests.get('https://a...content-available-to-author-only...y.org')
  9. response.raise_for_status() # Raise an exception for bad status codes
  10. return response.text
  11. except requests.exceptions.RequestException as e:
  12. print(f"Error getting public IP: {e}")
  13. return None
  14.  
  15. if __name__ == "__main__":
  16. public_ip = get_public_ip()
  17. if public_ip:
  18. print(f"Your public IP address is: {public_ip}")
Success #stdin #stdout 1.01s 36584KB
stdin
Standard input is empty
stdout
Error getting public IP: HTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x14f8a04018e0>: Failed to resolve 'api.ipify.org' ([Errno -3] Temporary failure in name resolution)"))