diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-05 17:28:44 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-05 17:28:44 +0200 |
commit | 6d8932da8be8df7d754fe3f4ac5df45ee0865590 (patch) | |
tree | 95de109df1cf2adcd6c8016092db012026930216 /bin | |
parent | 3c1b147437f6d1a3dea83fa5d4c10d315095b9b4 (diff) |
fix authentication problems for updating feeds
Diffstat (limited to 'bin')
-rw-r--r-- | bin/updater.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/bin/updater.py b/bin/updater.py index a5ff0042d..0644d91e3 100644 --- a/bin/updater.py +++ b/bin/updater.py @@ -35,10 +35,12 @@ class UpdateThread(threading.Thread): lock = threading.Lock() - def __init__(self, feeds, update_url): + def __init__(self, feeds, update_url, user, password): super().__init__() self.feeds = feeds self.update_url = update_url + self.user = user + self.password = password def run(self): with UpdateThread.lock: @@ -59,6 +61,11 @@ class UpdateThread(threading.Thread): url = '%s?%s' % (self.update_url, data) try: + auth = urllib.request.HTTPPasswordMgrWithDefaultRealm() + auth.add_password(None, url, self.user, self.password) + auth_handler = urllib.request.HTTPBasicAuthHandler(auth) + opener = urllib.request.build_opener(auth_handler) + urllib.request.install_opener(opener) urllib.request.urlopen(url, timeout=60) except urllib.error.HTTPError as e: print('%s: %s' % (url, e)) @@ -68,10 +75,12 @@ class UpdateThread(threading.Thread): class Updater: - def __init__(self, base_url, thread_num, interval): + def __init__(self, base_url, thread_num, interval, user, password): self.thread_num = thread_num self.interval = interval self.base_url = base_url + self.user = user + self.password = password if self.base_url[-1] != '/': self.base_url += '/' @@ -93,7 +102,7 @@ class Updater: # start thread_num for feeds threads = [] for num in range(0, self.thread_num): - thread = UpdateThread(feeds, self.update_url) + thread = UpdateThread(feeds, self.update_url, self.user, self.password) thread.start() threads.append(thread) @@ -135,7 +144,7 @@ def main(): urllib.request.install_opener(opener) # create the updater and run the threads - updater = Updater(args.url, args.threads, args.interval) + updater = Updater(args.url, args.threads, args.interval, args.user, args.password) updater.run() |