If you're having problems getting your public IP, you can try the below endpoint.
https://ip2location.io/ip
It just returns a plain text with the IPv4 or IPv6 address.
If you need JSON as well as other basic geolocation data, you can try the below endpoint.
https://api.ip2location.io/