requests.codes.ok - python examples

Here are the examples of the python api requests.codes.ok taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : calient.py
Copyright Apache License 2.0
Author : bachng2017
def _get_circuit_from_port(self,switch,switch_port_id,circuit_types):
    """ Returns a list of circuit that this `switch-port-id` belongs to

    The `circuit_types` includes ``incircuit`` , ``outcircuit`` or ``empty`` if there
    is no cicicuit at all
    """
    cli = self._clients[switch]
    session = cli['session']
    ip = cli['ip']
    result = []
    rest_result = session.get("http://%s/rest/ports/?id=detail&port=%s" % (ip,switch_port_id))
    if rest_result.status_code == requests.codes.ok:
        for entry in circuit_types:
            tmp = rest_result.json()[0][entry]
            if tmp != "": result.append(tmp)
    return result

3 View Complete Implementation : ixbps.py
Copyright Apache License 2.0
Author : bachng2017
def close(self):
    """ Closes the connection to the BP box
    """
    cli = self._clients[self._cur_name]
    ix  = cli['connection']
    result = ix.delete(self._base_url + '/auth/session',verify=False)
    if result.status_code != requests.codes.ok:
        BuiltIn().log(result)
        Exception('ERROR: could not logout')
    BuiltIn().log("Closed the connection")

3 View Complete Implementation : helper.py
Copyright GNU Affero General Public License v3.0
Author : skalenetwork
def get(url_name, params=None):
    host, cookies = get_node_creds(config)
    url = construct_url(host, ROUTES[url_name])

    response = get_request(url, cookies, params)
    if response is None:
        return None

    if response.status_code != requests.codes.ok:
        print('Request failed, status code:', response.status_code)
        return None

    json = response.json()
    if json['res'] != 1:
        print_err_response(response.json())
        return None
    else:
        return json['data']

3 View Complete Implementation : user.py
Copyright GNU Affero General Public License v3.0
Author : skalenetwork
def logout_user(config):
    host = safe_get_config(config, 'host')
    url = construct_url(host, ROUTES['logout'])
    response = get_request(url)
    if response is None:
        return None

    if response.status_code == requests.codes.ok:
        clean_cookies(config)
        print('Cookies removed')
    else:
        print('Logout failed:')
        print(response.text)

3 View Complete Implementation : logs_test.py
Copyright GNU Affero General Public License v3.0
Author : skalenetwork
def test_dump(config, skip_auth):
    archive_filename = 'skale-logs-dump-2019-10-08-17:40:00.tar.gz'
    resp_mock = response_mock(
        requests.codes.ok,
        headers={
            'Content-Disposition': f'attachment; filename="{archive_filename}"'
        },
        raw=BytesIO()
    )
    with mock.patch('requests.get') as req_get_mock:
        req_get_mock.return_value.__enter__.return_value = resp_mock
        result = run_command(dump, ['.'])
        astert result.exit_code == 0
        astert result.output == f'File {archive_filename} downloaded\n'

    if os.path.exists(archive_filename):
        os.remove(archive_filename)

3 View Complete Implementation : node_test.py
Copyright GNU Affero General Public License v3.0
Author : skalenetwork
def test_node_info_node_info(skip_auth, config):
    response_data = {'name': 'test', 'ip': '0.0.0.0',
                     'publicIP': '1.1.1.1',
                     'port': 10001,
                     'publicKey': '0x7',
                     'start_date': 1570114466,
                     'leaving_date': 0,
                     'last_reward_date': 1570628924, 'second_address': 0,
                     'status': 2, 'id': 32, 'owner': '0x23'}

    resp_mock = response_mock(
        requests.codes.ok,
        json_data={'data': response_data, 'res': 1}
    )
    result = run_command_mock('core.core.get_request', resp_mock, node_info)
    astert result.exit_code == 0
    astert result.output == '--------------------------------------------------\nNode info\nName: test\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nStatus: Active\n--------------------------------------------------\n'  # noqa

3 View Complete Implementation : controller_proxy.py
Copyright MIT License
Author : prodo-dev
    def create_snapshot(self, image_metadata: dict, context: BinaryIO) -> \
            Iterator[JSONString]:
        metadata_bytes = json.dumps(image_metadata).encode('utf-8')
        request_data = itertools.chain(io.BytesIO(metadata_bytes),
                                       io.BytesIO(b'\n'), context)
        response = self.server.post('snapshots',
                                    data=request_data,
                                    stream=True)
        _check_status(response, requests.codes.ok)
        return (frag.decode('utf-8') for frag in response.raw)

3 View Complete Implementation : controller_proxy.py
Copyright MIT License
Author : prodo-dev
    def get_logs(self, execution_id: str, since: Optional[int]) \
            -> Iterator[bytes]:
        response = self.server.get(
            'executions',
            execution_id,
            'logs',
            params={'since': since} if since is not None else {},
            stream=True)
        _check_status(response, requests.codes.ok)
        # Do not read in chunks as otherwise the logs don't flow interactively
        return response.raw

3 View Complete Implementation : controller_proxy.py
Copyright MIT License
Author : prodo-dev
    def get_user_last_execution_id(self, user: str) -> Optional[str]:
        response = self.server.get('users', user, 'last_execution_id')
        _check_status(response, requests.codes.ok)
        response_object = json.loads(response.content)
        # TODO: Make it consistent with the input data methods, and return None
        if 'execution_id' in response_object:
            return response_object['execution_id']
        else:
            # TODO: when used with `plz last` the error should be different
            # This bad behaviour is prior to plz serverless
            raise ValueError('Expected an execution ID')

3 View Complete Implementation : controller_proxy.py
Copyright MIT License
Author : prodo-dev
    def put_input(self, input_id: str, input_metadata: InputMetadata,
                  input_data_stream: BinaryIO) -> None:
        response = self.server.put(
            'data',
            'input',
            input_id,
            data=input_data_stream,
            stream=True,
            params={
                'user': input_metadata.user,
                'project': input_metadata.project,
                'path': input_metadata.path,
                'timestamp_millis': input_metadata.timestamp_millis
            })
        _check_status(response, requests.codes.ok)
        if input_id != response.json()['id']:
            raise CLIException('Got wrong input id back from the server')