summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2022-08-30 09:29:19 -0500
committerArtem Bityutskiy <dedekind1@gmail.com>2022-09-07 15:53:19 +0300
commit74b5ae6b03dffb26d7cf97fb2976d78f390e4b1f (patch)
treec0eeddb98ed3ae78dceddec109605943369bfbbb
parentbe06475d724336deb7fefe002c67371b9f9f907b (diff)
Fix failures when .netrc is not present
If the user doesn't have a .netrc file, bmaptool would fail. Fix this so that missing or incorrectly formatted .netrc files are not fatal Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
-rw-r--r--bmaptools/TransRead.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/bmaptools/TransRead.py b/bmaptools/TransRead.py
index e162eba..a36d3bc 100644
--- a/bmaptools/TransRead.py
+++ b/bmaptools/TransRead.py
@@ -590,11 +590,17 @@ class TransRead(object):
username = parsed_url.username
password = parsed_url.password
- if not username and not password:
- auth = netrc.netrc().authenticators(parsed_url.hostname)
- if auth:
- username = auth[0]
- password = auth[2]
+ if not username and not password and parsed_url.scheme in ("http", "https"):
+ try:
+ n = netrc.netrc()
+ auth = n.authenticators(parsed_url.hostname)
+ if auth:
+ username = auth[0]
+ password = auth[2]
+ except FileNotFoundError:
+ pass
+ except netc.NetrcParseError as e:
+ _log.error(f"Error parsing line {e.lineno} of {e.filename}: {e.msg}")
if username and password:
# Unfortunately, in order to handle URLs which contain user name