I would check your Network Security Group rules (builtin L3 / L4 firewall in Azure). Maybe the script tries to establish a connection outside of what is allowed by default.
By default, all NSG allow outbound connectivity to the Internet:
But, they don't allow any inbound connectivity outside these 3 default rules, which won't help you in this case since they are only there for internal communication (VNet, Load Balancer and Deny all).
If you know the IP address the VM is trying to communicate with, you can use Network Watcher available in Azure that will help you identify the security rules that is preventing the connection:
--I hope this helps. Please Accept it as an answer and "Up-Vote" the answer or message(s) that helped you so that it can help others in the community looking for help on similar topics