From 72fc49abe6e5ef1bd81192f478410fa98b53cb65 Mon Sep 17 00:00:00 2001 From: Kev <kev@flujos.org> Date: Fri, 15 Nov 2013 12:32:07 -0600 Subject: [PATCH] http auth --- mwclient/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mwclient/client.py b/mwclient/client.py index eead6d6..c64296e 100644 --- a/mwclient/client.py +++ b/mwclient/client.py @@ -7,6 +7,7 @@ import random import sys import weakref import socket +import base64 try: import json @@ -50,14 +51,15 @@ class Site(object): def __init__(self, host, path='/w/', ext='.php', pool=None, retry_timeout=30, max_retries=25, wait_callback=lambda *x: None, clients_useragent=None, - max_lag=3, compress=True, force_login=True, do_init=True): + max_lag=3, compress=True, force_login=True, do_init=True, httpauth=None): # Setup member variables self.host = host self.path = path self.ext = ext self.credentials = None self.compress = compress - + if httpauth: + self.httpauth = httpauth self.retry_timeout = retry_timeout self.max_retries = max_retries self.wait_callback = wait_callback @@ -220,7 +222,9 @@ class Site(object): headers['Content-Type'] = 'application/x-www-form-urlencoded' if self.compress and gzip: headers['Accept-Encoding'] = 'gzip' - + if self.httpauth: + credentials = base64.encodestring('%s:%s' % self.httpauth).replace('\n', '') + headers['Authorization'] = "Basic %s" % credentials token = self.wait_token((script, data)) while True: try: -- GitLab