Easiest Way to Poll A Web Server
<p>I have a job that I want to run a specific time each day. The job should look at a web server to see if a file exists. If it exists, I want to download the file and do something with it. If it doesn't, then I want to wait a minute and then try again.  </p>

<p>At the moment I just have a <code>try-except</code> statement that catches the exception if the file doesn't exist and then sleeps, and passes the file back to the calling function if it does. The works okay, but I feel like it's a rather cumbersome solution.  </p>

<p>Is there an accepted, or even just more Pythonic, way to achieve this? There are no asynchronous or threading considerations.</p>

<pre><code>import requests
import sleep

while True:
    r = requests.get("http://www.domain.com/fileYouAreMonitoring.bin")
    if r.status_code == 200:
        # we got the file!
        # exit or wait until next day, use break to escape while loop
    else:
        time.sleep(60)
</code></pre>

python