Skip to content
Snippets Groups Projects
Commit c80c1ca8 authored by Dan Michael O. Heggø's avatar Dan Michael O. Heggø
Browse files

Merge pull request #27 from kyv/master

Add support for http authentification
parents b6de90e7 72fc49ab
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import random ...@@ -7,6 +7,7 @@ import random
import sys import sys
import weakref import weakref
import socket import socket
import base64
try: try:
import json import json
...@@ -50,14 +51,15 @@ class Site(object): ...@@ -50,14 +51,15 @@ class Site(object):
def __init__(self, host, path='/w/', ext='.php', pool=None, retry_timeout=30, 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_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 # Setup member variables
self.host = host self.host = host
self.path = path self.path = path
self.ext = ext self.ext = ext
self.credentials = None self.credentials = None
self.compress = compress self.compress = compress
if httpauth:
self.httpauth = httpauth
self.retry_timeout = retry_timeout self.retry_timeout = retry_timeout
self.max_retries = max_retries self.max_retries = max_retries
self.wait_callback = wait_callback self.wait_callback = wait_callback
...@@ -220,7 +222,9 @@ class Site(object): ...@@ -220,7 +222,9 @@ class Site(object):
headers['Content-Type'] = 'application/x-www-form-urlencoded' headers['Content-Type'] = 'application/x-www-form-urlencoded'
if self.compress and gzip: if self.compress and gzip:
headers['Accept-Encoding'] = '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)) token = self.wait_token((script, data))
while True: while True:
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment