def _request(self, endpoint, method="GET", lookup=None, data={}, params={}, userargs=None, password=None):
"""
Generic request method designed to handle any morango endpoint.
:param endpoint: constant representing which morango endpoint we are querying
:param method: HTTP verb/method for request
:param lookup: the pk value for the specific object we are querying
:param data: dict that will be form-encoded in request
:param params: dict to be sent as part of URL's query string
:param userargs: Authorization credentials
:param password:
:return: ``Response`` object from request
"""
# convert user arguments into query str for passing to auth layer
if isinstance(userargs, dict):
userargs = "&".join(["{}={}".format(key, val) for (key, val) in iteritems(userargs)])
# build up url and send request
if lookup:
lookup = lookup + '/'
url = urljoin(urljoin(self.base_url, endpoint), lookup)
auth = (userargs, password) if userargs else None
resp = requests.request(method, url, json=data, params=params, auth=auth)
resp.raise_for_status()
return resp
评论列表
文章目录