Use a tool such as wireshark
(which needs to be run with sudo
on most distributions) to log the individual network packets when your code makes the API requests, to determine what is taking so long.
My guess is the following possibilities are most likely:
- For some reason your Ubuntu installation is picking up the wrong DNS server list, and DNS lookups are timing out.
- IPv6 issue (which may appear to be a DNS issue, too). Disable IPv6.