I assume with the sleep below you mean "retrying in 10 seconds"?

Also, the number of seconds should be pulled out into a constant.