Skip to content

Commit

Permalink
tolerate the insecure request to the server at the start
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgolec committed Jun 12, 2024
1 parent 550acf1 commit ab3c2a5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions schwab/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import requests
import sys
import time
import urllib3
import warnings
import webbrowser

Expand Down Expand Up @@ -223,17 +224,16 @@ def client_from_login_flow(api_key, app_secret, callback_url, token_path,

# Attempt to send a request to the server
try:
resp = requests.get(
'https://127.0.0.1:{}/schwab-py-internal/status'.format(
callback_port))
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', category=urllib3.exceptions.InsecureRequestWarning)

# pragma: no cover
resp = requests.get(
'https://127.0.0.1:{}/schwab-py-internal/status'.format(
callback_port), verify=False)
break
except requests.exceptions.ConnectionError as e:
# Treat refusal to connect due to a self-signed certificate as a
# sign that the server is running properly
if 'self-signed certificate' in str(e):
break
pass

time.sleep(0.1)

Expand All @@ -251,15 +251,13 @@ def client_from_login_flow(api_key, app_secret, callback_url, token_path,
while now < timeout_time:
# Attempt to fetch from the queue
try:
print(timeout_time - now)
callback_url = output_queue.get(
timeout=min(timeout_time - now, 0.1))
break
except queue.Empty:
pass

now = time.time()
print(now)

# Clean up and create the client
psutil.Process(server.pid).kill()
Expand Down

0 comments on commit ab3c2a5

Please sign in to comment.