When Safari works and a command-line tool doesn’t, or the other way round, a proxy setting is one of the usual suspects. macOS can print the proxy configuration it actually applies.
The option is --proxy, and it needs no sudo:
scutil --proxy
The man page says it reports the current system proxy configuration. On a Mac without a proxy you see little more than an exceptions list, typically *.local and 169.254/16. If a proxy is set you’ll see keys like HTTPEnable, HTTPProxy and HTTPPort, or ProxyAutoConfigEnable with a URL when a PAC file decides.
That last one is worth spotting. Company networks and some security apps push a PAC file, and then traffic goes through a proxy that you never typed in anywhere.
Why check here and not in System Settings? This is the merged result, including settings that came from a configuration profile or a VPN, so I trust it more than one tab in one network service.
Keep in mind that not every program asks the system. Many command-line tools such as curl ignore this configuration and look at environment variables like https_proxy instead. So if scutil --proxy is clean and a terminal tool still uses a proxy, run env | grep -i proxy.
Further reading: scutil.8 man page