當前位置: 首頁>>代碼示例>>Python>>正文


Python codes.ok方法代碼示例

本文整理匯總了Python中requests.codes.ok方法的典型用法代碼示例。如果您正苦於以下問題:Python codes.ok方法的具體用法?Python codes.ok怎麽用?Python codes.ok使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在requests.codes的用法示例。


在下文中一共展示了codes.ok方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: request

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def request(params):
  search, p = "https://derpibooru.org/api/v1/json/search/images", format_params(params)

  request = get(search, params=p)

  while request.status_code == codes.ok:
    images, image_count = request.json()["images"], 0
    for image in images:
      yield image
      image_count += 1
    if image_count < 50:
      break

    p["page"] += 1

    request = get(search, params=p) 
開發者ID:joshua-stone,項目名稱:DerPyBooru,代碼行數:18,代碼來源:request.py

示例2: _get_metadata

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def _get_metadata(self, request):
        """
        This method retrieves values from metadata service.

        request -- The request part after the metadata service address, for example if full request is:
                   'http://169.254.169.254/latest/meta-data/placement/availability-zone/'
                   then the request part is 'latest/meta-data/placement/availability-zone/'.
        """
        from requests import Session, codes
        from requests.adapters import HTTPAdapter
        try:
            session = Session()
            session.mount("http://", HTTPAdapter(max_retries=self._MAX_RETRIES))
            result = session.get(self.metadata_server + request, timeout=self._REQUEST_TIMEOUT)
        except Exception as e:
            raise MetadataRequestException("Cannot access metadata service. Cause: " + str(e))
        if result.status_code is not codes.ok:
            raise MetadataRequestException("Cannot retrieve configuration from metadata service. Status code: " + str(result.status_code))
        return str(result.text) 
開發者ID:awslabs,項目名稱:collectd-cloudwatch,代碼行數:21,代碼來源:setup.py

示例3: test_get_products

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def test_get_products(authorized_rider_sandbox_client, server_token_client):
    """Test to fetch products with access token and server token."""
    clients = [authorized_rider_sandbox_client, server_token_client]

    for client in clients:
        response = client.get_products(START_LAT, START_LNG)
        assert response.status_code == codes.ok

        # assert response looks like products information
        response = response.json
        products = response.get('products')
        assert len(products) >= PRODUCTS_AVAILABLE
        assert isinstance(products, list)

        for product in products:
            assert EXPECTED_PRODUCT_KEYS.issubset(product) 
開發者ID:uber,項目名稱:rides-python-sdk,代碼行數:18,代碼來源:test_client.py

示例4: test_get_price_estimates

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def test_get_price_estimates(authorized_rider_sandbox_client,
                             server_token_client
                             ):
    """Test to fetch price estimates with access token and server token."""
    clients = [authorized_rider_sandbox_client, server_token_client]

    for client in clients:
        response = client.get_price_estimates(
            START_LAT,
            START_LNG,
            END_LAT,
            END_LNG,
            UFP_SHARED_SEAT_COUNT,
        )
        assert response.status_code == codes.ok

        # assert response looks like price estimates
        response = response.json
        prices = response.get('prices')
        assert len(prices) >= PRODUCTS_AVAILABLE
        assert isinstance(prices, list)

        for price in prices:
            assert EXPECTED_PRICE_KEYS.issubset(price) 
開發者ID:uber,項目名稱:rides-python-sdk,代碼行數:26,代碼來源:test_client.py

示例5: test_get_pickup_time_estimates

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def test_get_pickup_time_estimates(
    authorized_rider_sandbox_client,
    server_token_client,
):
    """Test to fetch time estimates with access token and server token."""
    clients = [authorized_rider_sandbox_client, server_token_client]

    for client in clients:
        response = client.get_pickup_time_estimates(
            START_LAT,
            START_LNG,
        )
        assert response.status_code == codes.ok

        # assert response looks like pickup time estimates
        response = response.json
        times = response.get('times')
        assert len(times) >= PRODUCTS_AVAILABLE
        assert isinstance(times, list)

        for pickup_time in times:
            assert EXPECTED_TIME_KEYS.issubset(pickup_time) 
開發者ID:uber,項目名稱:rides-python-sdk,代碼行數:24,代碼來源:test_client.py

示例6: test_get_promotions

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def test_get_promotions(authorized_rider_sandbox_client, server_token_client):
    """Test to fetch promotions with access token and server token."""
    clients = [authorized_rider_sandbox_client, server_token_client]

    for client in clients:
        response = client.get_promotions(
            START_LAT,
            START_LNG,
            END_LAT,
            END_LNG,
        )
        assert response.status_code == codes.ok

        # assert response looks like promotions
        response = response.json
        assert EXPECTED_PROMOTION_KEYS.issubset(response) 
開發者ID:uber,項目名稱:rides-python-sdk,代碼行數:18,代碼來源:test_client.py

示例7: test_estimate_shared_ride

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def test_estimate_shared_ride(authorized_rider_sandbox_client):
    """Test to estimate a shared ride."""
    try:
        response = authorized_rider_sandbox_client.estimate_ride(
            product_id=UFP_SHARED_PRODUCT_ID,
            seat_count=UFP_SHARED_SEAT_COUNT,
            start_latitude=START_LAT,
            start_longitude=START_LNG,
            end_latitude=END_LAT,
            end_longitude=END_LNG,
        )
    except Exception as e:
        print(e.errors[0].__dict__)
    assert response.status_code == codes.ok

    # assert response looks like price and time estimates
    response = response.json
    fare = response.get('fare')
    assert EXPECTED_ESTIMATE_RIDE_FARE_KEYS.issubset(fare)
    trip = response.get('trip')
    assert EXPECTED_ESTIMATE_SHARED_RIDE_TRIP_KEYS.issubset(trip) 
開發者ID:uber,項目名稱:rides-python-sdk,代碼行數:23,代碼來源:test_client.py

示例8: test_estimate_ride

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def test_estimate_ride(authorized_rider_sandbox_client):
    """Test to fetch ride estimate with access token."""
    response = authorized_rider_sandbox_client.estimate_ride(
        product_id=UFP_PRODUCT_ID,
        start_latitude=START_LAT,
        start_longitude=START_LNG,
        end_latitude=END_LAT,
        end_longitude=END_LNG,
    )
    assert response.status_code == codes.ok

    # assert response looks like price and time estimates
    response = response.json
    fare = response.get('fare')
    assert EXPECTED_ESTIMATE_RIDE_FARE_KEYS.issubset(fare)
    trip = response.get('trip')
    assert EXPECTED_ESTIMATE_RIDE_TRIP_KEYS.issubset(trip) 
開發者ID:uber,項目名稱:rides-python-sdk,代碼行數:19,代碼來源:test_client.py

示例9: log_in

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def log_in(self):
        login_params = dict(username=self.username, password=self.password, json=True)
        try:
            response = self.session.post(self.api_gettoken_url, params=login_params)
            if response.status_code == request_codes.ok:
                resp_json = response.json()
                self.login_token = resp_json.get('Token')
                self.user_id = resp_json.get('UserId')
                self.token_exp = dateutil.parser.parse(resp_json.get('ExpirationDate'))

                region.set("titlovi_token", [self.user_id, self.login_token, self.token_exp])
                logger.debug('New token obtained')

            elif response.status_code == request_codes.unauthorized:
                raise AuthenticationError('Login failed')

        except RequestException as e:
            logger.error(e) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:20,代碼來源:titlovi.py

示例10: test_create_index

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def test_create_index(elasticsearch):
    response = elasticsearch.create_index('creation_test_index')
    assert response.status_code == codes.ok
    assert response.json()['acknowledged'] is True
    assert elasticsearch.get('/creation_test_index').status_code == codes.ok 
開發者ID:elastic,項目名稱:elasticsearch-docker,代碼行數:7,代碼來源:test_xpack_basic_index_crud.py

示例11: test_delete_index

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def test_delete_index(elasticsearch):
    elasticsearch.create_index('deletion_test_index')
    response = elasticsearch.delete_index('deletion_test_index')
    assert response.status_code == codes.ok
    assert response.json()['acknowledged'] is True
    assert elasticsearch.get('/deletion_test_index').status_code == codes.not_found 
開發者ID:elastic,項目名稱:elasticsearch-docker,代碼行數:8,代碼來源:test_xpack_basic_index_crud.py

示例12: is_server_accessible

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def is_server_accessible(self):
        """
        Check if FURS server is accessible. Will return False if server responds with anything else
        than HTTP Code: 200 or if the request timeouts.

        :return: (boolean) True for ok, False if there was a problem accessing server.
        """
        try:
            return self.connector.send_echo().status_code == codes.ok
        except Timeout as e:
            return False 
開發者ID:boris-savic,項目名稱:python-furs-fiscal,代碼行數:13,代碼來源:base_api.py

示例13: _send_request

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def _send_request(self, path, data):
        """
        Sends request to the FURS Server and decodes response.

        :param path: (string) Server path
        :param data: (dict) Data to be sent
        :return: (dict) Received response

        :raises:
            ConnectionTimedOutException: If connection timed out
            ConnectionException: If FURS responded with status code different than 200
            FURSException: If server responded with error
        """
        try:
            response = self.connector.post(path=path, json=data)

            if response.status_code == codes.ok:
                # TODO - we should verify server signature!
                server_response = json.loads(jws.get_unverified_claims(response.json()['token']))
                return self._check_for_errors(server_response)
            else:
                raise ConnectionException(code=response.status_code,
                                          message=response.text)

        except Timeout as e:
            raise ConnectionTimedOutException(e) 
開發者ID:boris-savic,項目名稱:python-furs-fiscal,代碼行數:28,代碼來源:base_api.py

示例14: get_image_data

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def get_image_data(id_number):
  url = "https://derpibooru.org/api/v1/json/images/{}".format(id_number)

  request = get(url)

  if request.status_code == codes.ok:
    data = request.json()

    if "duplicate_of" in data:
      return get_image_data(data["duplicate_of"])
    else:
      return data 
開發者ID:joshua-stone,項目名稱:DerPyBooru,代碼行數:14,代碼來源:request.py

示例15: _get_metadata

# 需要導入模塊: from requests import codes [as 別名]
# 或者: from requests.codes import ok [as 別名]
def _get_metadata(self, request): 
        """
        This method retrieves values from metadata service.
        
        request -- The request part after the metadata service address, for example if full request is:
                   'http://169.254.169.254/latest/meta-data/placement/availability-zone/' 
                   then the request part is 'latest/meta-data/placement/availability-zone/'.
        """
        result = self.session.get(self.metadata_server + request, timeout=self._REQUEST_TIMEOUT)
        if result.status_code is codes.ok:
            return str(result.text)
        else:
            self._LOGGER.error("The request: '" + str(request) + "' failed with status code: '" + str(result.status_code) + "' and message: '" + str(result.text) +"'.")
            raise MetadataRequestException("Cannot retrieve configuration from metadata service. Status code: " + str(result.status_code)) 
開發者ID:awslabs,項目名稱:collectd-cloudwatch,代碼行數:16,代碼來源:metadatareader.py


注:本文中的requests.codes.ok方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。