How to use the botocore.vendored.requests function in botocore

To help you get started, we’ve selected a few botocore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless / enterprise-plugin / integration-testing / wrapper-service / handler.py View on Github external
def success(event, context):
    with context.serverless_sdk.span('create sts client'):
        sts = boto3.client('sts')
    sts.get_caller_identity()
    requests.get('https://httpbin.org/get')
    return 'success'
github aws / aws-cli / tests / unit / customizations / s3 / fake_session.py View on Github external
beginning = range_components[0]
                end = range_components[1]
                if end == '':
                    body = body[int(beginning):]
                else:
                    body = body[int(beginning):(int(end) + 1)]
            mock_response = BytesIO(body)
            mock_response.set_socket_timeout = Mock()
            response_data['Body'] = mock_response
            etag = self.session.s3[bucket][key]['ETag']
            response_data['ETag'] = etag + '--'
        else:
            response_data['Errors'] = [{'Message': 'Bucket does not exist'}]
        if self.session.connection_error:
            self.session.connection_error = False
            raise requests.ConnectionError
        return FakeHttp(), response_data
github rackerlabs / ebs_snapper / ebs_snapper / utils.py View on Github external
pass

    # maybe we have API keys from boto3?
    try:
        LOG.debug('get_owner_id: IAM')
        iam_client = boto3.client('iam')
        return [iam_client.get_user()['User']['Arn'].split(':')[4]]
    except:
        pass

    # if we're _inside_ an EC2 instance
    try:
        LOG.debug('get_owner_id: EC2 Metadata Service')
        from botocore.vendored import requests
        s_url = 'http://169.254.169.254/latest/meta-data/iam/info/'
        return [requests.get(s_url, timeout=1).json()['InstanceProfileArn'].split(':')[4]]
    except:
        pass

    # try using EC2 instances with account_ids for owners
    if region is not None:
        LOG.debug('get_owner_id: EC2 region %s', region)
        regions = [region]
    else:
        LOG.debug('get_owner_id: EC2 all regions')
        regions = get_regions(must_contain_instances=True)

    owners = []
    for r in regions:
        client = boto3.client('ec2', region_name=r)
        instances = client.describe_instances()
        owners.extend([x['OwnerId'] for x in instances['Reservations']])
github ijin / ecs-deity / github.py View on Github external
if body['trigger_word'] != stage:
        return respond(None, {"text": "invalid repository"})
    if not applicable_branch(branch):
        return respond(None, {"text": "not applicable branch name"})

    message =  "Going to create " + repo + " env for `" + branch + "`"
    j = { "text": message }

    data =  {
        "ref": branch,
        "repository": {"name": repo},
        "ref_type": "branch"
    }
    gw_url = os.environ['gw_url']  + "/github"
    r = requests.post(gw_url, json=data, headers={"X-GitHub-Event": "create"})
    print(r.status_code, r.reason)

    return respond(None, j)
github abhinavbom / clara / scan.py View on Github external
def slack_notification(result):
    webhook_url = 'https://hooks.slack.com/services/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'
    response = requests.post(webhook_url, json={'text': result})
    http_reply = {"statusCode": 200, "body": response.text}
    return http_reply
github iopipe / iopipe-python / iopipe / contrib / logger / request.py View on Github external
def upload_log_data(url, stream_or_file, config):
    """
    Uploads log data to IOpipe.

    :param url: The signed URL
    :param stream_or_file: The log data stream or file
    :param config: The IOpipe config
    """
    try:
        logger.debug("Uploading log data to IOpipe")
        if isinstance(stream_or_file, StringIO):
            stream_or_file.seek(0)
            response = requests.put(
                url, data=stream_or_file, timeout=config["network_timeout"]
            )
        else:
            with open(stream_or_file, "rb") as data:
                response = requests.put(
                    url, data=data, timeout=config["network_timeout"]
                )
        response.raise_for_status()
    except Exception as e:
        logger.debug("Error while uploading log data: %s", e)
        logger.exception(e)
        if hasattr(e, "response") and hasattr(e.response, "content"):
            logger.debug(e.response.content)
    else:
        logger.debug("Log data uploaded successfully")
    finally:
github awslabs / aws-cloudformation-templates / community / custom_resources / python_custom_resource_helper / crhelper.py View on Github external
response_body['RequestId'] = event['RequestId']
    response_body['LogicalResourceId'] = event['LogicalResourceId']
    if response_data and response_data != {} and response_data != [] and isinstance(response_data, dict):
        response_body['Data'] = response_data

    json_response_body = json.dumps(response_body)

    logger.debug("Response body:\n{}".format(json_response_body))

    headers = {
        'content-type': '',
        'content-length': str(len(json_response_body))
    }

    try:
        response = requests.put(response_url,
                                data=json_response_body,
                                headers=headers)
        logger.info("CloudFormation returned status code: {}".format(response.reason))
    except Exception as e:
        logger.error("send(..) failed executing requests.put(..): {}".format(e))
        raise
github NickKuts / Libby / lambda_func / book_info.py View on Github external
long, defaults to GET
    :param pretty_print: if the resulting JSON should be prettyprinted, '1' for
    yes and '0' for no, defaults to '0'
    :return: a dictionary with 'status_code' from the request and 'json'
    """
    params = {
        'lookfor': [term],
        'filter[]': [
            'building:"0/AALTO/"',
        ] + filter,
        'field[]': field,
        'prettyPrint': [pretty_print],
        'lng': ['en-gb']
    }

    sess = requests.Session()
    sess.headers.update(__headers)
    sess.params.update(params)

    r = sess.request(url=__url + 'search', method=method)
    sess.close()

    print(r.url)
    # print(r.json())
    # print("result count: " + str(r.json()['resultCount']))
    return {'status_code': r.status_code, 'json': r.json()}
github attobot / attobot / AttoBotDeleter / lambda_function.py View on Github external
def errorissue(repo_fullname, user, message):
    r = requests.post(urljoin(GITHUB_API, "repos", repo_fullname, "issues"),
            auth=(BOT_USER, BOT_PASS),
            json={
                "title": "Error tagging new release",
                "body": message + "\ncc: @" + user
                })
    raise Exception(message)