I am using a raspberry pi zero w. The script runs when the pi is manually connected to a computer via a USB. We are viewing the interface with a VNC viewer. The script written is trying to connect to the internet, and once an internet connection has been established it will continue through the rest of the script. When we click run inside VNC, the code works perfectly. We have sent the script to the pi by putting the file under rc.local so that it runs when the raspberry pi is booted up without being connected to the computer. However, the program seems to be getting stuck in the checking internet connection loop and does not connect to the internet. We know it is getting stuck there because we coded in an initial buzzer when the device boots up, and then another buzz when the internet connection has been established. I am unsure why it would work correctly when connected to the computer, and not when it is booting up on the pi.
@I. Patel wrote in his comment: "We figured out what our issue was. We had downloaded a dropbox uploader file onto the user pi, but when the pi was running it was using user root. So we had to change in rc.local to make sure the script was being run as user pi and not user root."