Skip to content

Instantly share code, notes, and snippets.

@marshyski
Created April 20, 2015 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshyski/30eeafd3de2b1bf616ef to your computer and use it in GitHub Desktop.
Save marshyski/30eeafd3de2b1bf616ef to your computer and use it in GitHub Desktop.
Wait for website listening on port 443 to become available
import configuration as config
from subprocess import call
import requests
import time, socket
''' Turn off SSL errors '''
requests.packages.urllib3.disable_warnings()
''' Wait for port 443 is listening '''
while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
conn = s.connect_ex((pub_ip, 443))
if conn == 0:
break
except:
print "Waiting for port 443 to listen on"
time.sleep(20)
''' Make web request with basic auth and get status code '''
r = requests.get('https://' + pub_ip, auth=(config.USERNAME, config.PASSWORD), verify=False)
if r.status_code == 200:
''' Open website in web browser '''
call (['open', 'https://' + pub_ip])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment