def fetch(method, uri, params_prefix=None, **params):
params = urlencode(_prepare_params(params, params_prefix))<EOL>binary_params = params.encode('<STR_LIT>')<EOL>url = "<STR_LIT>" % (CHALLONGE_API_URL, uri)<EOL>req = Request(url, binary_params)<EOL>req.get_method = lambda: method<EOL>user, api_key = get_credentials()<EOL>auth_handler = HTTPBasicAuthHandler()<EOL>auth_handler.add_password(<EOL>realm="<STR_LIT>",<EOL>uri=req.get_full_url(),<EOL>user=user,<EOL>passwd=api_key<EOL>)<EOL>opener = build_opener(auth_handler)<EOL>try:<EOL><INDENT>response = opener.open(req)<EOL><DEDENT>except HTTPError as e:<EOL><INDENT>if e.code != <NUM_LIT>:<EOL><INDENT>raise<EOL><DEDENT>doc = ElementTree.parse(e).getroot()<EOL>if doc.tag != "<STR_LIT>":<EOL><INDENT>raise<EOL><DEDENT>errors = [e.text for e in doc]<EOL>raise ChallongeException(*errors)<EOL><DEDENT>return response<EOL>
Fetch the given uri and return the contents of the response.