Here are the examples of the python api requests.__getattribute__ taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
0
View Complete Implementation : request_handler.py
Copyright MIT License
Author : cronofy
Copyright MIT License
Author : cronofy
def _request(self, request_method, endpoint='', url='', data=None, params=None, use_api_key=False, omit_api_version=False):
"""Perform a http request via the specified method to an API endpoint.
:param string request_method: Request method.
:param string endpoint: Target endpoint. (Optional).
:param string url: Override the endpoint and provide the full url (eg for pagination). (Optional).
:param dict params: Provide parameters to past to the request. (Optional).
:param dict data: Data to past to the post. (Optional).
:return: Response
:rtype: ``Response``
"""
if not data:
data = {}
if not params:
params = {}
if endpoint and omit_api_version and not url:
url = '%s/%s' % (self.base_url, endpoint)
if endpoint and not url:
url = '%s/%s/%s' % (self.base_url, settings.API_VERSION, endpoint)
if use_api_key:
headers = {
'Authorization': self.auth.get_api_key(),
'User-Agent': self.user_agent,
}
else:
headers = {
'Authorization': self.auth.get_authorization(),
'User-Agent': self.user_agent,
}
response = requests.__getattribute__(request_method)(
url=url,
hooks=settings.REQUEST_HOOK,
headers=headers,
json=data,
params=params
)
if ((response.status_code != 200) and (response.status_code != 202)):
try:
response.raise_for_status()
except requests.exceptions.HTTPError as e:
raise PyCronofyRequestError(
request=e.request,
response=e.response,
)
return response
0
View Complete Implementation : ipyrest.py
Copyright MIT License
Author : deeplook
Copyright MIT License
Author : deeplook
def execute_request(url: str,
method: str = 'get',
headers: Dict = {},
params: Dict = {},
json: Dict = {},
recorder: Optional[vcr.VCR] = recorder,
castette_path: str = '',
logger: Optional[MyLogger] = None) -> Tuple[requests.models.Response, bool]:
"""
Execute a HTTP request and return response defined by the `requests` package.
"""
if logger:
logger.logger.info(
'execute_request {} {}'.format(recorder, castette_path))
is_cached = False
method_func = requests.__getattribute__(method.lower())
if castette_path and recorder:
from vcr.castette import Castette
from vcr.request import Request
logger.logger.info('imported vcr')
req = Request(method.upper(), url,
'irrelevant body?', {'some': 'header'})
logger.logger.info('req ' + str(req))
c_path = os.path.join(recorder.castette_library_dir, castette_path)
logger.logger.info(c_path)
logger.logger.info(Castette(None).load(path=c_path))
if req in Castette(None).load(path=c_path):
is_cached = True
with recorder.use_castette(c_path):
logger.logger.info('running...')
if json:
resp = method_func(url, headers=headers, params=params, json=json)
else:
resp = method_func(url, headers=headers, params=params)
logger.logger.info('got it...')
else:
if json:
resp = method_func(url, headers=headers, params=params, json=json)
else:
resp = method_func(url, headers=headers, params=params)
# FIXME: requests.post('http://httpbin.org/post', json={"key": "value"})
return resp, is_cached
0
View Complete Implementation : utils.py
Copyright Apache License 2.0
Author : filestack
Copyright Apache License 2.0
Author : filestack
def __getattr__(self, name):
if name in ('get', 'post', 'put', 'delete'):
return partial(self.handle_request, name)
return original_requests.__getattribute__(name)