GVKun编程网logo

ssh key error

11

在本文中,我们将带你了解sshkeyerror在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的'serverlessinvoke-fhello'给出KeyError、(Error)SQLC

在本文中,我们将带你了解ssh key error在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的'serverless invoke -f hello'给出KeyError、(Error)SQL CODE -530, ERROR THE INSERT OR UPDATE VALUE OF FOREIGN KEY PAY$ID$U 无效、Asp.net core 学习笔记 ef core Surrogate Key, Natural Key, Alternate Keys、discord.ext.commands.errors.CommandInvokeError:命令引发异常:KeyError:'rank'

本文目录一览:

ssh key error

ssh key error

Permissions 0755 for ''/root/.ssh/id_rsa'' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /root/.ssh/id_rsa
root@localhost''s password:
[root@B ~]# chmod 0600 /root/.ssh/id_rsa
[root@B ~]# ssh root@localhost
Last login: Wed Apr 27 15:19:55 2016 from 114.xx.xx.xx
[root@B ~]# exit

'serverless invoke -f hello'给出KeyError

'serverless invoke -f hello'给出KeyError

如何解决''serverless invoke -f hello''给出KeyError?

我正在关注一个教程,以学习如何使用无服务器框架。目标是部署Django应用程序。本教程建议将必要的环境变量放在单独的yml文件中。不幸的是,按照教程进行操作会给我带来KeyError。 我有一个serverless.yml,variables.yml和handler.py。我将对所有下面的代码以及给定的错误进行认证。

serverless.yml:

service: serverless-django
custom: ${file(./variables.yml)}
provider:
  name: aws
  runtime: python3.8
functions:
  hello:
    environment: 
      - THE_ANSWER: ${self:custom.THE_ANSWER}
    handler: handler.hello

variables.yml:

THE_ANSWER: 42

handler.py:

import os

def hello(event,context):
    return {
        "statusCode": 200,"body": "The answer is: " + os.environ["THE_ANSWER"]
    }

我的终端中的错误:

{
    "errorMessage": "''THE_ANSWER''","errorType": "KeyError","stackTrace": [
        "  File \"/var/task/handler.py\",line 7,in hello\n    \"body\": \"The answer is: \" + os.environ[\"THE_ANSWER\"]\n","  File \"/var/lang/lib/python3.8/os.py\",line 675,in __getitem__\n    raise KeyError(key) from None\n"
    ]
}
 
  Error --------------------------------------------------
 
  Error: Invoked function Failed
      at AwsInvoke.log (/snapshot/serverless/lib/plugins/aws/invoke/index.js:105:31)
      at AwsInvoke.tryCatcher (/snapshot/serverless/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/snapshot/serverless/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/snapshot/serverless/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/snapshot/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/snapshot/serverless/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/snapshot/serverless/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/snapshot/serverless/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/snapshot/serverless/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate._onImmediate (/snapshot/serverless/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:456:21)
      at process.topLevelDomainCallback (domain.js:137:15)
 
     For debugging logs,run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment information ---------------------------
     Operating System:          linux
     Node Version:              12.18.1
     Framework Version:         2.0.0 (standalone)
     Plugin Version:            4.0.2
     SDK Version:               2.3.1
     Components Version:        3.1.2

我正在尝试的命令是''sls invoke -f hello''。命令“ sls deploy”已经成功执行。

我是无服务器新手,所以请让我知道如何解决此问题,或者是否需要更多信息。

解决方法

首先,yml脚本中存在错误:

无服务器错误---------------------------------------

环境变量0中的无效字符

The error is defining environment variables as an array instead of key-value pairs

然后在部署之后,一切都会顺利进行( sls deploy -v

sls调用--f你好

{ “状态代码”:200, “ body”:“答案是:42” }


serverless.yml

service: sls-example

custom: ${file(./variables.yml)}

provider:
  name: aws
  runtime: python3.8

functions:
  hello:
    environment:
        THE_ANSWER: ${self:custom.THE_ANSWER}
    handler: handler.hello

variables.yml

THE_ANSWER: 42

(Error)SQL CODE -530, ERROR THE INSERT OR UPDATE VALUE OF FOREIGN KEY PAY$ID$U 无效

(Error)SQL CODE -530, ERROR THE INSERT OR UPDATE VALUE OF FOREIGN KEY PAY$ID$U 无效

如何解决(Error)SQL CODE -530, ERROR THE INSERT OR UPDATE VALUE OF FOREIGN KEY PAY$ID$U 无效?

错误来自付款表。它说 PAY_ID_U 的插入值不正确。问题是什么?下面的代码片段是两个表的插入值的一部分。

Here are the tables invoice and payment

INSERT INTO PAYMENT                                            
  VALUES(''0100'',''00100'',''DEBIT'',''33456A'',''2021-01-20'',1856.54);
INSERT INTO PAYMENT                                            
  VALUES(''0110'',''00110'',''CREDIT'',''11223E'',''2020-02-02'',56.78); 
INSERT INTO PAYMENT                                            
  VALUES(''0120'',''00120'',''NONE'',''55334Z'',''2020-12-22'',88.99);   

INSERT INTO INVOICE                                                 
  VALUES(''0100'',''TARGET'',''2019-01-08'',100.00,''OPEN'');       
INSERT INTO INVOICE                                                 
  VALUES(''0110'',''MORTGAGE'',1856.96,''PAID'');    
INSERT INTO INVOICE                                                 
  VALUES(''0120'',''VERSACE'',''2020-08-20'',985.97,''UNPAID'');    

解决方法

Db2 在这里表现正确,它说没有像“00100”这样的发票键(第一次插入付款)。原因是您的 invoice.inv_id 是 CHAR(5),但是当您插入到 invoice 中时,您在发票键的 values 语句中只指定了四个字符,缺少前导零!

顺便说一句,最好始终明确命名插入列的名称。

因此将插入语句更改如下,注意密钥长度为 5 个字符:

INSERT INTO INVOICE (inv_id,inv_id_u,inv_desc,inv_date,inv_amt,inv_status)
    VALUES(''00100'',''00100'',''TARGET'',''2019-01-08'',100.00,''OPEN'');    


INSERT INTO INVOICE (inv_id,inv_status)
  VALUES(''00110'',''00110'',''MORTGAGE'',''2021-01-20'',1856.96,''PAID'');    

INSERT INTO INVOICE (inv_id,inv_status)
  VALUES(''00120'',''00120'',''VERSACE'',''2020-08-20'',985.97,''UNPAID'');    

Asp.net core 学习笔记 ef core Surrogate Key, Natural Key, Alternate Keys

Asp.net core 学习笔记 ef core Surrogate Key, Natural Key, Alternate Keys

更新 : 2020-01-05

今天记入一下 alternate key 遇到的主次疑惑

alternate 会产生多个 foreignkey 的情况

比如我想选一个 state 那么前提是我要先选 country, 这样就需要有 2 个 foreignkey 

所谓的主次疑惑是说在上面这个情况下我是要一个 state 所以当这个 state 换 country 后, 我也是要跟着它走的. 整个都是 cascade update.

另一种情况可能是我先选了一个 country, 然后我想再选一个 state, 这种情况下, country 是确定的. state 是依赖 country 的,

这时候如果 state 突然换了 country, 那么我其实是不想跟着换的,反而要阻止它,因为逻辑错了。

 

 

 

更新: 2019-12-23

在 ef 如果要拿不是 Id 来做 foreignkey 那么它就肯定是 alternative key 了, 

当我们调用 HasPrincipalKey 这个时候 alternative key 就自动被做出来了。

在 sql 的话,其实并没有这么一个条件. 

 

 

更新: 2019-11-01

虽然 Natural Key 很自然,但是维护起来成本很挺高

ef core 给了我们 Alternate Keys + composition 

但是目前依然没有解决修改的问题

https://github.com/aspnet/EntityFrameworkCore/issues/4073

 

里面提到了使用 update cascade 的做法,虽然很不错,但是 sql server 的 cascade 不可以 multiple path

https://stackoverflow.com/questions/851625/foreign-key-constraint-may-cause-cycles-or-multiple-cascade-paths

https://support.microsoft.com/en-us/help/321843/error-message-1785-occurs-when-you-create-a-foreign-key-constraint-tha

sql server 官方给出的意见是使用 trigger instand of 

这个方法和 cascade 有很大区别的,正常情况下 cascade 的逻辑是交给子表,这种情况下扩展一个新的表是无需修改之前任何代码的。

但是如果使用了 trigger 就不得不把所有的逻辑放到一起了. 

我们只能使用 trigger instand of  不可以使用 trigger after 因为 foreignkey 约束会直接报错而导致 delete 没有被执行,而 trigger 自然也不会触发了

所以只能使用 instand of, instand of 不是 before ,它的意思是替代,也就是说你得自己写过 delete 逻辑. 

delete 尚可接受,但是 alternative key 需要 cascade update, 这个 update 语句可就不好写了.. 

https://dba.stackexchange.com/questions/77273/instead-of-trigger-continue-with-operation-after-custom-logic

目前我的做法是当遇到 cascade cycle 时, 把逻辑写在 application 而不交给 sql server trigger.

cascade update 手动维护需要暂时解开约束

https://stackoverflow.com/questions/159038/how-can-foreign-key-constraints-be-temporarily-disabled-using-t-sql

类似

alter table People nocheck constraint FK_People_Countries;
update People set country = ''Singapore2'' where country = ''Singapore'';
update Countries set name = ''Singapore2'' where name = ''Singapore'';
alter table People with check check constraint FK_People_Countries;

 

 

 

 

更新: 2019-10-27 

https://docs.microsoft.com/en-us/ef/core/modeling/relationships

https://docs.microsoft.com/en-us/ef/core/modeling/alternate-keys

 

composition alternate keys 

有些时候 key 需要 2 个 column 才可以.比如很常见的 country, state

country 和 state 是 1-n 的关系

address 里需要记入 country and state 

如果关系只是 country 1-n address 和 state 1-n address 的话

我们就无法确保, state 是 under country 的

这个时候就可以用 composition alternate keys 了

modelBuilder.Entity<Country>().HasAlternateKey(p => p.name);
modelBuilder.Entity<Country>().HasMany(p => p.states).WithOne(p => p.country).HasForeignKey(p => p.countryKey).HasPrincipalKey(p => p.name).OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Country>().Property(p => p.name).IsRequired(true).HasMaxLength(32);
modelBuilder.Entity<Country>().HasMany(p => p.people).WithOne(p => p.country)
    .HasForeignKey(p => p.countryKey)
    .HasPrincipalKey(p => new { p.name }).OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity<State>().HasAlternateKey(p => new { p.countryKey, p.name });
modelBuilder.Entity<State>().Property(p => p.name).IsRequired(true).HasMaxLength(32);
modelBuilder.Entity<State>().HasMany(p => p.people).WithOne(p => p.state)
    .HasForeignKey(p => new { p.countryKey, p.stateKey })
    .HasPrincipalKey(p => new { p.countryKey, p.name });

 

 

 

 

Surrogate Key vs Natural Key, 争论多年 

https://www.mssqltips.com/sqlservertip/5431/surrogate-key-vs-natural-key-differences-and-when-to-use-in-sql-server/

2 个都有好处坏处. 

ef core 对 Natural Key 支持比较弱. 

使用 Alternate Keys 来实现

https://docs.microsoft.com/en-us/ef/core/modeling/alternate-keys

它最糟糕的地方是,目前不支持修改 

https://stackoverflow.com/questions/36200436/cannot-update-alternate-key-entity-framework-core-1-0

https://github.com/aspnet/EntityFrameworkCore/issues/4073

 

对我来说大部分情况下 Surrogate Key 是好用的

但它凡事都要 join 表比较麻烦, filter 也好,查询值也好,都一定要 join.

所以我认为 Natural Key 只在一种情况下特别好

join 的 table 只是一个 primary column

比如有个 category 和 product 

category 只有一个 name, 如果做一个 category 表那每次 product 就得 join category 为了拿唯一的 category name。

而如果 product 直接记入 category name 就方便多了. 

 

短期内 ef 应该是不会支持 update 这个功能的,saveChanges 就报错说不能 edit 了,

目前的 workaround 是去 override migration 生成出来的 file 添加 onUpdate cascade,

table.ForeignKey(
    name: "FK_Products_Categories_categoryName",
    column: x => x.categoryName,
    principalTable: "Categories",
    principalColumn: "name",
    onDelete: ReferentialAction.Restrict,
    onUpdate: ReferentialAction.Cascade);

然后更新的时候直接调用语句.  

var commandText = "update Categories set name = @categoryName where Id = @Id";
var categoryName = new SqlParameter("@categoryName", "man");
var Id = new SqlParameter("@Id", 1);
var ok = Db.Database.ExecuteSqlCommand(commandText, new[] { categoryName, Id });

 

discord.ext.commands.errors.CommandInvokeError:命令引发异常:KeyError:'rank'

discord.ext.commands.errors.CommandInvokeError:命令引发异常:KeyError:'rank'

如何解决discord.ext.commands.errors.CommandInvokeError:命令引发异常:KeyError:''rank''?

我正在尝试创建一个 Hypixel API 命令,但如果此人没有等级,我会收到错误消息。 我的代码:

@import requests

@commands.command() 
    async def api(self,ctx):
        user = ctx.message.content[5:]
        key = "#############"
        r2 = requests.get(f"https://api.mojang.com/users/profiles/minecraft/{user}")
        uuid = r2.json()
        r = requests.get(f"https://api.hypixel.net/player?key={key}&uuid={uuid[''id'']}")
        d = r.json()

        e = discord.Embed(color=0xff7373)
        e.set_author(name=f"{uuid[''name'']}''s Hypixel Stats:")
        e.set_thumbnail(url=f"https://mc-heads.net/avatar/{uuid[''id'']}.png")
        e.add_field(name="Rank:",value=d[''player''][''rank''].capitalize())
        e.add_field(name="bedwars Wins:",value=d[''player''][''achievements''][''bedwars_wins''])
        e.set_footer(text=f"UUID: {uuid[''id'']}")

        await ctx.send(embed=e)

解决方法

您可以捕获异常:

try:
    e.add_field(name="Rank:",value=d[''player''][''rank''].capitalize())
except KeyError:
    pass

仅当玩家具有实际排名时,才会添加排名字段。

关于ssh key error的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于'serverless invoke -f hello'给出KeyError、(Error)SQL CODE -530, ERROR THE INSERT OR UPDATE VALUE OF FOREIGN KEY PAY$ID$U 无效、Asp.net core 学习笔记 ef core Surrogate Key, Natural Key, Alternate Keys、discord.ext.commands.errors.CommandInvokeError:命令引发异常:KeyError:'rank'等相关内容,可以在本站寻找。

本文标签: