Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch_url: optional flag to disable warning logs #197

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def dt2js(self, dt):
def dt2ts(self, dt):
return time.mktime(dt.timetuple())

def fetch_url(self, url, username=None, password=None, timeout=2):
def fetch_url(self, url, username=None, password=None, timeout=2, warn_no_connect=1):
headers = {'Accept': 'text/plain'}
plain = True
if url.startswith('https'):
Expand All @@ -72,7 +72,8 @@ def fetch_url(self, url, username=None, password=None, timeout=2):
try:
conn.request("GET", purl, headers=headers)
except Exception as e:
logger.warning("Problem fetching {0}: {1}".format(url, e))
if warn_no_connect == 1:
logger.warning("Problem fetching {0}: {1}".format(url, e))
conn.close()
return False
resp = conn.getresponse()
Expand Down