Skip to content

Commit

Permalink
httplib debugging not enabled by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
yalnazov committed Nov 18, 2015
1 parent a377ec9 commit e3bb458
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
4 changes: 2 additions & 2 deletions paymill/paymill_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class PaymillContext(object):
Use the getter methods in order to access the required PAYMILL service.
"""

def __init__(self, api_key):
def __init__(self, api_key, http_debug_enabled=False):
"""
:param str api_key: your PAYMILL private key
:rtype : PaymillContext
"""
self.api_url = 'https://api.paymill.com/v2.1'
self.api_key = api_key
self.http_client = http_client.HTTPClient(self.api_url, api_key, "")
self.http_client = http_client.HTTPClient(self.api_url, api_key, "", http_debug_enabled)
self.client_service = client_service.ClientService(self.http_client)
self.offer_service = offer_service.OfferService(self.http_client)
self.payment_service = payment_service.PaymentService(self.http_client)
Expand Down
20 changes: 7 additions & 13 deletions paymill/utils/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
from requests import Session
from ..utils import abstract_http_client
from .pm_error import PMError
import logging
# these two lines enable debugging at httplib level (requests->urllib3->httplib)
# you will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# the only thing missing will be the response.body which is not logged.
from six.moves import http_client
http_client.HTTPConnection.debuglevel = 1

logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests
logging.getLogger().setLevel(logging.INFO)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.ERROR)
requests_log.propagate = True

def http_debug(enabled=False):
if enabled:
# these two lines enable debugging at httplib level (requests->urllib3->httplib)
from six.moves import http_client
http_client.HTTPConnection.debuglevel = 1

class HTTPClient(abstract_http_client.AbstractHTTPClient):
def __init__(self, base_url, user_name, user_pass=''):
def __init__(self, base_url, user_name, user_pass='', http_debug_enabled=False):
"""Initialize a new paymill interface connection. Requires a private key."""
self.base_url = base_url
self.session = Session()
Expand All @@ -27,6 +20,7 @@ def __init__(self, base_url, user_name, user_pass=''):
self.operations = dict(GET=self.get, POST=self.post, PUT=self.put, DELETE=self.delete)
#for internal usage
self.response = None
http_debug(enabled=http_debug_enabled)

def __call__(self, request_type, params, url, return_type):
try:
Expand Down

0 comments on commit e3bb458

Please sign in to comment.