当前位置: 首页 > 知识库问答 >
问题:

Boto服务器错误:终结点已存在,具有相同的令牌,但属性不同

左劲
2023-03-14

我的应用程序返回以下错误:

BotoServerError:BotoServerError:400错误请求{“错误”:{“代码”:“InvalidParameter”,“消息”:“无效参数:令牌原因:endpoint[myendpoint]已存在,具有相同的令牌,但具有不同的属性。”,“类型”:“发件人”},“请求ID”:“myrequestid”}

我模仿了我的代码http://mobile.awsblog.com/post/Tx223MJB0XKV9RU/Mobile-token-management-with-Amazon-SNS 为了避免这种问题,但我不知道是什么原因造成的,也不知道如何解决。无论我是从SNS控制台删除endpoint,还是将数据库中的endpointarn设置为NULL,或者两者都设置为NULL,这似乎并不重要。请帮忙!

def createEndpoint(sns_conn, applicationArn, testUser, token):
    cpe_result = sns_conn.create_platform_endpoint(applicationArn, token, str(testUser.userid))
    try:
            endpointArn = cpe_result["CreatePlatformEndpointResponse"]["CreatePlatformEndpointResult"]["EndpointArn"]
    except BotoServerError, e:
            if "already exists with the same Token, but different attributes" in e.error_message:
                    s = e.error_message
                    endpointArn = s[s.index("Endpoint ") + len("Endpoint "):s.index("already exists") - 1]
            else:
                    raise
    testUser.endpointarn = endpointArn
    db.session.commit()
    return endpointArn

def registerWithSNS(testUser):
    # Adaptation of code from http://mobile.awsblog.com/post/Tx223MJB0XKV9RU/Mobile-token-management-with-Amazon-SNS
    endpointArn = testUser.endpointarn
    token = request.form["token"]
    platform = request.form["platform"]
    updateNeeded = False
    createNeeded = endpointArn == None

    # Init sns_conn and applicationArn
    sns_conn = sns.connect_to_region("eu-west-1")
    lpa_response = sns_conn.list_platform_applications()
    platformApps = lpa_response["ListPlatformApplicationsResponse"]["ListPlatformApplicationsResult"]["PlatformApplications"]
    if platform == "Android":
            requiredSuffix = "GCM"
    elif platform == "iOS":
            requiredSuffix = "APNS"        
    else:
            raise Exception("Unknown platform: '{}'".format(platform))
    applicationArn = None
    for pa in platformApps:
            if pa["PlatformApplicationArn"].endswith(requiredSuffix):
                    applicationArn = pa["PlatformApplicationArn"]
                    break
    if applicationArn == None:
            raise Exception("Missing SNS platform application for '{}'".format(platform))

    if createNeeded:
            # No endpoint ARN is stored; need to call createEndpoint
            endpointArn = createEndpoint(sns_conn, applicationArn, testUser, token)
            createNeeded = False

    # Look up the endpoint and make sure the data in it is current, even if
    # it was just created
    try:
            gea_result = sns_conn.get_endpoint_attributes(endpointArn)
            returnedToken = gea_result["GetEndpointAttributesResponse"]["GetEndpointAttributesResult"]["Attributes"]["Token"]
            returnedEnabled = gea_result["GetEndpointAttributesResponse"]["GetEndpointAttributesResult"]["Attributes"]["Enabled"]
            updateNeeded = (returnedToken != token) or (returnedEnabled != "true")
    except BotoServerError, e:
            if e.error_code == "NotFound":
                    # we had a stored ARN, but the endpoint associated with it
                    # disappeared. Recreate it.
                    createNeeded = True
            else:
                    raise

    if createNeeded:
            createEndpoint(sns_conn, applicationArn, testUser, token)

    if updateNeeded:
            # endpoint is out of sync with the current data;
            # update the token and enable it.
            attribs = {}
            attribs["Token"] = token
            attribs["Enabled"] = "true"
            sns_conn.set_endpoint_attributes(endpointArn, attribs)

共有1个答案

宗波涛
2023-03-14

脸掌。createEndpoint中的try只需要再高一行。。。

 类似资料:
  • 我正在创建一个简单的社交图,用户可以在其中创建一个帖子,标记它,并对它进行评论。我用py2neo做模型。该模型具有和作为节点。用户在上、或。在我的例子中,单个用户可以在单个上创建多个或(就像其他任何社交网络一样)。根据我的模型,这需要多个或关系,但具有不同的属性。模型是这样建立的: 我运行以下操作来构建图形: 我希望有两个关系,如下所示: 但我看到事实并非如此: 那么,我的问题是双重的。(1)可以

  • 在 Serenity 中,服务终结点是 ASP.NET MVC 控制器的一个子类。 这是 Northwind 的 OrderEndpoint 摘录: namespace Serene.Northwind.Endpoints { [RoutePrefix("Services/Northwind/Order"), Route("{action}")] [ConnectionKey("N

  • 问题内容: 我有一个REST API,它返回JSON响应为: 有时它返回: 我有一个像这样的POJO: 那么,有没有一种方法(不是写你自己的其他 自定义解串器 中)Jackson2,这将有助于我映射在JSON来时,它的A型和类型时,它是一个JSON对象? 或者换句话说,在Jackson中,有没有一种方法可以按变量而不是by 映射? 问题答案: 我可以建议您像这样使用JsonNode: 或像这样 :

  • 我试图找到一个没有属性的元素的XPath。它只能通过其父级的属性来识别。然而,父级也不具有唯一属性。 例如: 这里有两个元素。如何获得第二个元素。上面的语法为我提供了第一个元素。。但是,如果我使用: 我得到一个错误消息"xpath表达式 '//*[@id="btn"][2]/ul/li[2]/a/span'无法计算或不会导致WebElement"

  • 我需要在所有具有相同属性值的节点之间创建关系。 例如,我可以使用以下查询: 但是如果我有大约200K的节点,这个脚本运行的时间相当长。 有没有其他更快的方法来建立这样的关系? 谢谢

  • 我正在尝试将OAuth添加到使用Spring框架开发的rest服务中。我正在使用基于注释的配置和Spring Boot来运行它。 在我的项目中,我有以下课程: 我的授权服务器配置如下: 当我向终端发出GET请求时,我被要求输入HTTP基本凭据。当我尝试使用用户登录时,以下内容会被记录下来 输入用户名为工作,但我不知道它的密码。默认密码被记录,但也不起作用。 那么这个密码是什么?我在哪里能找到它?我