api: Fix using staging.humbughq.com as the base_url.

urlparse.urljoin(base_url, url) will drop any path inside base_url if
either the url has a leading "/" or base_url doesn't have a trailing
"/".  So adjust our API bindings to ensure that doesn't happen.

(imported from commit c080ee8c04b89127888609da28afc8b388af1911)
This commit is contained in:
Tim Abbott 2013-06-27 12:09:41 -04:00
parent 3bdd446651
commit e2a74b0613
1 changed files with 4 additions and 2 deletions

View File

@ -41,7 +41,7 @@ assert(LooseVersion(requests.__version__) >= LooseVersion('0.12.1'))
# In newer versions, the 'json' attribute is a function, not a property # In newer versions, the 'json' attribute is a function, not a property
requests_json_is_function = callable(requests.Response.json) requests_json_is_function = callable(requests.Response.json)
API_VERSTRING = "/v1/" API_VERSTRING = "v1/"
def generate_option_group(parser): def generate_option_group(parser):
group = optparse.OptionGroup(parser, 'API configuration') group = optparse.OptionGroup(parser, 'API configuration')
@ -97,6 +97,8 @@ class Client(object):
self.base_url = "https://api.humbughq.com" self.base_url = "https://api.humbughq.com"
if self.base_url != "https://api.humbughq.com" and not self.base_url.endswith("/api"): if self.base_url != "https://api.humbughq.com" and not self.base_url.endswith("/api"):
self.base_url += "/api" self.base_url += "/api"
if not self.base_url.endswith("/"):
self.base_url += "/"
self.retry_on_errors = retry_on_errors self.retry_on_errors = retry_on_errors
self.client_name = client self.client_name = client
@ -122,7 +124,7 @@ class Client(object):
if self.verbose: if self.verbose:
if not query_state["had_error_retry"]: if not query_state["had_error_retry"]:
sys.stdout.write("humbug API(%s): connection error%s -- retrying." % \ sys.stdout.write("humbug API(%s): connection error%s -- retrying." % \
(url.split(API_VERSTRING, 2)[1], error_string,)) (url.split(API_VERSTRING, 2)[0], error_string,))
query_state["had_error_retry"] = True query_state["had_error_retry"] = True
else: else:
sys.stdout.write(".") sys.stdout.write(".")