Troubleshooting / Code Unable to Access the Internet
The script cannot access the external network, mostly due to DNS or firewall issues.
Specifically, when executing code similar to requests.get('http://www.baidu.com')
, the following errors occur:
Temporary failure in name resolution
Connection refused
Connection to www.baidu.com timed out
- Other network errors
You can perform the following operations in sequence to troubleshoot the issue:
- Execute
ping 114.114.114.114
on the host machine to check if the host can access the public network. - Execute
curl http://www.baidu.com
on the host machine to check if the host DNS is functioning properly. - Execute
docker exec -it {DataFlux Func (Automata) CONTAINERS ID} sh -c 'exec ping 114.114.114.114'
to check if the public network can be accessed from within the container. - Execute
docker exec -it {DataFlux Func (Automata) CONTAINERS ID} sh -c 'exec curl http://www.baidu.com -i'
to check if the DNS inside the container is functioning properly.
114.114.114.114
is the address of a commonly used public DNS server
If the installed DataFlux Func (Automata) image does not have the ping
command, you can also use the curl http://{Baidu IP address}
command as an alternative.
Possible causes and solutions:
Possible Cause | Solution |
---|---|
Host machine cannot access the public network, DNS is abnormal | Check and adjust the operating system network configuration |
Cannot access the public network from within the container, DNS is abnormal | Check and adjust Docker-related configurations, and check the operating system network configuration if necessary |
Docker DNS Configuration Reference
Edit the /etc/docker/daemon.json
file, add the following content, save it, and then restart the Docker service:
JSON | |
---|---|
1 2 3 4 5 6 |
|