当前位置: 首页>>代码示例>>Python>>正文


Python status.HTTP_503_SERVICE_UNAVAILABLE属性代码示例

本文整理汇总了Python中rest_framework.status.HTTP_503_SERVICE_UNAVAILABLE属性的典型用法代码示例。如果您正苦于以下问题:Python status.HTTP_503_SERVICE_UNAVAILABLE属性的具体用法?Python status.HTTP_503_SERVICE_UNAVAILABLE怎么用?Python status.HTTP_503_SERVICE_UNAVAILABLE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在rest_framework.status的用法示例。


在下文中一共展示了status.HTTP_503_SERVICE_UNAVAILABLE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_currency_exchange_rate

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def get_currency_exchange_rate(request, source_currency_code, target_currency_code):
    """
    Return currency conversion rate using source and target currency codes
    :param request:
    :param source_currency_code:
    :param target_currency_code:
    :return: 503 if Free Currency Converter api fails
    :return: 200 successful
    """
    query = "{0}_{1}".format(source_currency_code, target_currency_code)
    try:
        api_response = requests.get(CURRENCY_CONVERTER_API_URL.format(query))
        api_response_json = api_response.json()
        if not api_response.ok:
            return DOWNSTREAM_ERROR_RESPONSE

        response = CurrencyItem(source=source_currency_code,
                                target=target_currency_code,
                                result=api_response_json[query])

    except Exception:
        exception_message = "Incorrect currency codes {}".format(query)
        return Response(exception_message, status=status.HTTP_503_SERVICE_UNAVAILABLE)

    return Response(response.to_json()) 
开发者ID:project-travel-mate,项目名称:server,代码行数:27,代码来源:views.py

示例2: get_help

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def get_help(request):
    """
    Returns HELP content from static JSON file '/api/resources/help.json'
    :param request:
    :return: 200 successful
    """
    try:
        filename = 'api/resources/help.json'
        file = open(filename, 'r')
        data = file.read()
        data = json.loads(data)
        file.close()
    except (IOError, ValueError):
        data = {"help": ["Error in fetching content."]}
        return Response(data, status=status.HTTP_503_SERVICE_UNAVAILABLE)
    except Exception as e:
        return Response(str(e), status=status.HTTP_503_SERVICE_UNAVAILABLE)
    return Response(data, status=status.HTTP_200_OK) 
开发者ID:project-travel-mate,项目名称:server,代码行数:20,代码来源:views.py

示例3: test_create_domain_under_unsupported_public_suffix_rule

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def test_create_domain_under_unsupported_public_suffix_rule(self):
        # Show lenience if the PSL library produces an UnsupportedRule exception
        name = 'unsupported.wildcard.test'
        psl_cm = self.get_psl_context_manager(UnsupportedRule)
        with psl_cm, self.assertPdnsRequests():
            response = self.client.post(self.reverse('v1:domain-list'), {'name': name})
            self.assertStatus(response, status.HTTP_503_SERVICE_UNAVAILABLE) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:9,代码来源:test_domains.py

示例4: test_poll_peering_sessions

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def test_poll_peering_sessions(self):
        url = reverse(
            "peering-api:bgpgroup-poll-peering-sessions",
            kwargs={"pk": self.bgp_group.pk},
        )
        response = self.client.post(url, **self.header)
        self.assertStatus(response, status.HTTP_503_SERVICE_UNAVAILABLE) 
开发者ID:respawner,项目名称:peering-manager,代码行数:9,代码来源:test_api.py

示例5: test_available_peers

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def test_available_peers(self):
        url = reverse(
            "peering-api:internetexchange-available-peers",
            kwargs={"pk": self.internet_exchange.pk},
        )
        response = self.client.get(url, **self.header)
        self.assertStatus(response, status.HTTP_503_SERVICE_UNAVAILABLE) 
开发者ID:respawner,项目名称:peering-manager,代码行数:9,代码来源:test_api.py

示例6: test_import_peering_sessions

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def test_import_peering_sessions(self):
        url = reverse(
            "peering-api:internetexchange-import-peering-sessions",
            kwargs={"pk": self.internet_exchange.pk},
        )
        response = self.client.post(url, **self.header)
        self.assertStatus(response, status.HTTP_503_SERVICE_UNAVAILABLE) 
开发者ID:respawner,项目名称:peering-manager,代码行数:9,代码来源:test_api.py

示例7: test_configure_router

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def test_configure_router(self):
        url = reverse(
            "peering-api:internetexchange-configure-router",
            kwargs={"pk": self.internet_exchange.pk},
        )
        response = self.client.get(url, **self.header)
        self.assertStatus(response, status.HTTP_503_SERVICE_UNAVAILABLE)
        response = self.client.post(url, **self.header)
        self.assertStatus(response, status.HTTP_503_SERVICE_UNAVAILABLE) 
开发者ID:respawner,项目名称:peering-manager,代码行数:11,代码来源:test_api.py

示例8: get_city_trends

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def get_city_trends(request, city_id):
    """
    Returns a list of top trending tweets in the given city
    :param request:
    :param city_id:
    :return: 404 if invalid city id is sent
    :return: 503 if Twitter API request fails
    :return: 200 successful
    """
    try:
        city = City.objects.get(pk=city_id)
    except City.DoesNotExist:
        error_message = "Invalid City ID"
        return Response(error_message, status=status.HTTP_404_NOT_FOUND)

    twitter_auth = OAuth1(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_OAUTH_TOKEN,
                          TWITTER_OAUTH_TOKEN_SECRET)

    # check if city WOEID is in database or not
    if not city.woeid:
        try:
            url = TWITTER_TRENDS_URL + "closest.json?lat={0}&long={1}".format(city.latitude, city.longitude)
            woeid_response = requests.get(url, auth=twitter_auth)
            city.woeid = woeid_response.json()[0]['woeid']
            city.save()
        except Exception as e:
            return Response(str(e), status=status.HTTP_503_SERVICE_UNAVAILABLE)

    try:
        url = TWITTER_TRENDS_URL + "place.json?id={0}".format(city.woeid)
        api_response = requests.get(url, auth=twitter_auth)
        response = api_response.json()[0]['trends']
    except Exception:
        return DOWNSTREAM_ERROR_RESPONSE

    return Response(response) 
开发者ID:project-travel-mate,项目名称:server,代码行数:38,代码来源:views.py

示例9: get_shopping_info

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def get_shopping_info(request, query):
    """
    Returns a list of responses from
    :param request:
    :param query:
    :return: 503 Ebay request fails
    :return: 200 successful
    """
    try:
        api_response = requests.get(EBAY_API_URL.format(query))
        api_response_json = api_response.json()
        if not api_response.ok:
            error_message = api_response_json['errorMessage'][0]['error'][0]['message'][0]
            return Response(error_message, status=status.HTTP_503_SERVICE_UNAVAILABLE)

        #  if ebay api returns empty response with no items
        if api_response_json['findItemsAdvancedResponse'][0]['searchResult'][0]['@count'] == '0':
            return Response([], status=status.HTTP_400_BAD_REQUEST)

        response = []
        for item in api_response_json['findItemsAdvancedResponse'][0]['searchResult'][0]['item']:
            response.append(ShoppingItem(
                name=item['title'][0],
                url=item['viewItemURL'][0],
                image=item['galleryURL'][0],
                value=item['sellingStatus'][0]['currentPrice'][0]['__value__'],
                currency=item['sellingStatus'][0]['currentPrice'][0]['@currencyId'],
            ).to_json())

    except Exception:
        return DOWNSTREAM_ERROR_RESPONSE

    return Response(response) 
开发者ID:project-travel-mate,项目名称:server,代码行数:35,代码来源:views.py

示例10: get_all_restaurants

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def get_all_restaurants(request, latitude, longitude):
    """
    Returns restaurant details forecast for given city using coordinates
    :param request:
    :param latitude:
    :param longitude:
    :return: 503 if Zomato API fails
    :return: 200 successful
    """
    response = []
    try:
        url = GET_ALL_RESTAURANTS_API_URL.format(latitude, longitude)
        api_response = requests.get(url, headers=FOOD_API_REQUEST_HEADERS)
        api_response_json = api_response.json()
        if not api_response.ok:
            error_message = api_response_json['message']
            return Response(error_message, status=status.HTTP_503_SERVICE_UNAVAILABLE)

        for restaurant in api_response_json['nearby_restaurants']:
            restaurant_obj = restaurant['restaurant']
            response_obj = FoodResponse(id=restaurant_obj['id'],
                                        name=restaurant_obj['name'],
                                        url=restaurant_obj['url'],
                                        latitude=restaurant_obj['location']['latitude'],
                                        longitude=restaurant_obj['location']['longitude'],
                                        avg2=restaurant_obj['average_cost_for_two'],
                                        currency=restaurant_obj['currency'],
                                        image=restaurant_obj['featured_image'],
                                        rating=restaurant_obj['user_rating']['aggregate_rating'],
                                        votes=restaurant_obj['user_rating']['votes'],
                                        address=restaurant_obj['location']['address'])
            response.append(response_obj.to_json())
    except Exception:
        return DOWNSTREAM_ERROR_RESPONSE

    return Response(response) 
开发者ID:project-travel-mate,项目名称:server,代码行数:38,代码来源:views.py

示例11: get_restaurant

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def get_restaurant(request, restaurant_id):
    """
    Returns restaurant details for a given restaurant id
    :param request:
    :param restaurant_id:
    :return: 503 if Zomato API fails
    :return: 200 successful
    """
    try:
        url = GET_RESTAURANT_API_URL.format(restaurant_id)
        api_response = requests.get(url, headers=FOOD_API_REQUEST_HEADERS)
        api_response_json = api_response.json()
        if not api_response.ok:
            error_message = api_response_json['message']
            return Response(error_message, status=status.HTTP_503_SERVICE_UNAVAILABLE)
        response = FoodDetailedResponse(
            id=api_response_json['id'],
            name=api_response_json['name'],
            url=api_response_json['url'],
            address=api_response_json['location']['address'],
            longitude=api_response_json['location']['longitude'],
            latitude=api_response_json['location']['latitude'],
            avg2=api_response_json['average_cost_for_two'],
            price_range=api_response_json['price_range'],
            currency=api_response_json['currency'],
            img=api_response_json['featured_image'],
            agg_rating=api_response_json['user_rating']['aggregate_rating'],
            votes=api_response_json['user_rating']['votes'],
            deliver=api_response_json['has_online_delivery'],
            booking=api_response_json['has_table_booking'],
            cuisines=api_response_json['cuisines']
        ).to_json()
    except Exception:
        return DOWNSTREAM_ERROR_RESPONSE

    return Response(response) 
开发者ID:project-travel-mate,项目名称:server,代码行数:38,代码来源:views.py

示例12: get_city_weather

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def get_city_weather(request, city_id):
    """
    Return current city weather using city name
    :param request:
    :param city_id:
    :return: 404 if Invalid City ID is passed
    :return: 503 if OpenWeatherMap api fails
    :return: 200 successful
    """
    try:
        city = City.objects.get(pk=city_id)
    except City.DoesNotExist:
        error_message = "Invalid City ID"
        return Response(error_message, status=status.HTTP_404_NOT_FOUND)

    try:
        api_response = requests.get(OPEN_WEATHER_API_URL.format(city.latitude, city.longitude))
        api_response_json = api_response.json()
        if not api_response.ok:
            error_message = api_response_json['message']
            return Response(error_message, status=status.HTTP_503_SERVICE_UNAVAILABLE)

        response = WeatherResponse(temp=to_celsius(api_response_json['main']['temp']),
                                   max_temp=to_celsius(api_response_json['main']['temp_max']),
                                   min_temp=to_celsius(api_response_json['main']['temp_min']),
                                   code=api_response_json['weather'][0]['id'],
                                   condensed=api_response_json['weather'][0]['main'],
                                   description=api_response_json['weather'][0]['description'],
                                   icon=icon_to_url(api_response_json['weather'][0]['icon']),
                                   humidity=api_response_json['main']['humidity'],
                                   pressure=api_response_json['main']['pressure'])
    except Exception:
        return DOWNSTREAM_ERROR_RESPONSE

    return Response(response.to_json()) 
开发者ID:project-travel-mate,项目名称:server,代码行数:37,代码来源:views.py

示例13: get_multiple_days_weather

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def get_multiple_days_weather(request, num_of_days, city_name):
    """
    Returns 'num_of_days' forecast for given city using 'city_name'
    :param request:
    :param num_of_days:
    :param city_name:
    :return: 400 if number of days ar not in [1,16] range
    :return: 503 if OpenWeatherMap api fails
    :return: 200 successful
    """
    response = []
    if num_of_days >= 16 or num_of_days < 1:
        error_message = "Invalid number of days. Should be in between [1, 16]"
        return Response(error_message, status=status.HTTP_400_BAD_REQUEST)

    try:
        api_response = requests.get(OPEN_FORECAST_API_URL.format(city_name, num_of_days))
        api_response_json = api_response.json()
        if not api_response.ok:
            error_message = api_response_json['message']
            return Response(error_message, status=status.HTTP_503_SERVICE_UNAVAILABLE)

        for result in api_response_json['list']:
            response.append(WeatherResponse(max_temp=to_celsius(result['temp']['max']),
                                            min_temp=to_celsius(result['temp']['min']),
                                            code=result['weather'][0]['id'],
                                            condensed=result['weather'][0]['main'],
                                            description=result['weather'][0]['description'],
                                            icon=icon_to_url(result['weather'][0]['icon']),
                                            humidity=result['humidity'],
                                            pressure=result['pressure']).to_json())
    except Exception:
        return DOWNSTREAM_ERROR_RESPONSE

    return Response(response) 
开发者ID:project-travel-mate,项目名称:server,代码行数:37,代码来源:views.py

示例14: export_user_data

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def export_user_data(request: Request):
    """
    Export all user data in a zip blob and serve it through sendfile.
    """
    user = request.user

    # Cleanup old archives.
    cache_expiration = datetime.fromtimestamp(datetime.now().timestamp() - USER_EXPORT_DATA_CACHE_PERIOD)
    for archive in UserArchive.objects.filter(owner=user,
                                              updated_on__lte=cache_expiration).iterator():
        try:
            archive.local_archive.delete()
        except ValueError:
            pass
        finally:
            archive.delete()

    try:
        archive = UserArchive.objects.get(owner=user)
        return sendfile(request, archive.local_archive.path)
    except (UserArchive.DoesNotExist, OSError, IOError, ValueError):
        try:
            builder = UserDataArchiveBuilder(user)
            export(builder)
            archive, _ = UserArchive.objects.get_or_create(owner=user)
            builder.archive.close()  # save the ZIP file.
            archive.local_archive.save('data.zip',
                                       File(open(builder.archive_filename, 'rb')))
            builder.cleanup()
            return sendfile(request, archive.local_archive.path)
        except (OSError, IOError, django.db.Error) as e:
            print(e)
            return Response({}, status=status.HTTP_503_SERVICE_UNAVAILABLE) 
开发者ID:mangaki,项目名称:mangaki,代码行数:35,代码来源:user.py

示例15: test_status_empty_dict

# 需要导入模块: from rest_framework import status [as 别名]
# 或者: from rest_framework.status import HTTP_503_SERVICE_UNAVAILABLE [as 别名]
def test_status_empty_dict(self):
        """Test getting scheduler status with empty initialization"""

        url = '/%s/status/' % self.api
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_503_SERVICE_UNAVAILABLE, response.content)
        result = json.loads(response.content)
        self.assertDictEqual({'detail': 'Status is missing. Scheduler may be down.'}, result) 
开发者ID:ngageoint,项目名称:scale,代码行数:10,代码来源:test_views.py


注:本文中的rest_framework.status.HTTP_503_SERVICE_UNAVAILABLE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。