小编Daw*_*y33的帖子

给出确切路径时,AWS Boto3“密钥对不存在”错误

我正在运行以下脚本:

from __future__ import print_function

import paramiko
import boto3


#print('Loading function')

paramiko.util.log_to_file("/tmp/Dawny.log")

# List of EC2 variables
region = 'us-east-1'
image = 'ami-<>'
keyname = '<>.pem'

ec2 = boto3.resource('ec2')


instances = ec2.create_instances(ImageId=image, MinCount=1, MaxCount=1, InstanceType = 't2.micro', KeyName=keyname)

instance = instances[0]
instance.wait_until_running()

instance.load()

print(instance.public_dns_name)



def lambda_handler(event, context):
    instances = ec2.create_instances(ImageId=image, MinCount=1, MaxCount=1, InstanceType = 't2.micro', KeyName=keyname)

    instance = instances[0]
    instance.wait_until_running()

    instance.load()

    print(instance.public_dns_name)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到此错误

botocore.exceptions.ClientError: An error occurred (InvalidKeyPair.NotFound) when calling the RunInstances operation: The key pair '<>.pem' does not exist …
Run Code Online (Sandbox Code Playgroud)

python amazon-ec2 amazon-web-services boto3

3
推荐指数
1
解决办法
3806
查看次数

Flake8 抛出 B008 fastapi 数据类型定义

我有以下代码,它POST通过 处理请求fastapi。但是,flake8不断抛出B008 Do not perform function calls in argument defaults. The call is performed only once at function definition time错误。

@app.post("/predict", status_code=200)
def predict(
    page_no: int = Form(...), dimensions: list = Form(...), image: UploadFile = File(...)
) -> Dict[str, int]:
Run Code Online (Sandbox Code Playgroud)

有没有办法修复或解决这些警告?

python typing flake8 fastapi

3
推荐指数
1
解决办法
2938
查看次数

将输出写入python luigi的文件

我只是试图从文档中运行python luigi 示例:

class TaskA(luigi.Task):
    def output(self):
        return luigi.LocalTarget('xyz')

class FlipLinesBackwards(luigi.Task):
    def requires(self):
        return TaskA()

    def output(self):
        return luigi.LocalTarget('abc')

    def run(self):
        f = self.input().open('r') # this will return a file stream that reads from "xyz"
        g = self.output().open('w')
        for line in f:
           g.write('%s\n', ''.join(reversed(line.strip().split())))
        g.close() # needed because files are atomic
Run Code Online (Sandbox Code Playgroud)

我使用命令行运行它:

python Luigi_Test.py FlipLinesBackwards --local-scheduler
Run Code Online (Sandbox Code Playgroud)

我的印象是,这将在我运行它的目录中创建一个文件,但它没有?

难道我做错了什么?

python luigi

2
推荐指数
1
解决办法
1891
查看次数

如何在ansible-playbook命令中包含Ansible配置文件?

ansible-playbook在本地主机中运行以下命令:

ansible-playbook -i "localhost," -c local GitClone.yaml
Run Code Online (Sandbox Code Playgroud)

但是,我也有一个GitClone.cfg文件,其中包含:

[defaults]
transport = ssh

[ssh_connection]
ssh_args = -o ForwardAgent=yes
Run Code Online (Sandbox Code Playgroud)

GitClone.cfg文件与该文件位于同一目录中GitClone.yaml

如何在命令中包含此文件?

上面提到的命令没有拾取.cfg文件。

ansible

2
推荐指数
1
解决办法
4338
查看次数

如何附加未命名的 tmux 会话?

tmux ls 给我以下结果:

ubuntu@ip-10-x-y-z:~$ tmux ls
0: 1 windows (created Wed Aug 23 08:35:32 2017) [112x51]
1: 1 windows (created Wed Aug 23 09:06:27 2017) [112x51]
Run Code Online (Sandbox Code Playgroud)

如何附加列表中的第一个?

ubuntu tmux

2
推荐指数
2
解决办法
1760
查看次数

如何在FastAPI中接收图像和json数据?

我通过以下方式将图像和 json 数据发送到我的 API:

import requests
filename = "test_image.jpeg"
files = {'my_file': (filename, open(filename, 'rb'))}
json={'first': "Hello", 'second': "World"}

response = requests.post('http://127.0.0.1:8000/file', files=files, params=json)
Run Code Online (Sandbox Code Playgroud)

如何通过FastAPI在服务器端同时接收图像和json数据?

我的代码如下所示:

@app.post('/file')
def _file_upload(my_file: UploadFile = File(...), params: str = Form(...)):

    image_bytes = my_file.file.read()
    decoded = cv2.imdecode(np.frombuffer(image_bytes, np.uint8), -1)
    pg_image = cv2.resize(decoded, (220, 220))
    return {"file_size": params}
Run Code Online (Sandbox Code Playgroud)

但是,这给了我以下错误:

<Response [422]>
{'detail': [{'loc': ['body', 'params'], 'msg': 'field required', 'type': 'value_error.missing'}]}
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么吗?

python api fastapi

2
推荐指数
1
解决办法
1万
查看次数

'mv'命令抛出错误但在docker中执行正常

当我执行以下命令(将带有.txt.sbreaks扩展名的所有文件移动到另一个文件夹)时:

sudo docker exec name mv xyz/data/outputs/*.{sbreaks,txt} <>/data/spare
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

mv: cannot stat ‘xyz/data/outputs/*.sbreaks’: No such file or directory
mv: cannot stat ‘xyz/data/outputs/*.txt’: No such file or directory
Run Code Online (Sandbox Code Playgroud)

但是,当我进入docker sudo docker exec -it name bash并执行相同的命令时:mv xyz/data/outputs/*.{sbreaks,txt} xyz/data/spare它执行正常.

我在这做错了什么?

PS:本地和Docker容器都是ubuntu环境

bash ubuntu docker

1
推荐指数
1
解决办法
625
查看次数

为什么 Lambda 突然抛出“请求已过期”错误?

我的Lambda函数通过create_instancesboto3模块创建EC2服务器。

我从早上就开始触发这个 Lambda,它创建实例的效果很好。但突然间,我不断收到这个奇怪的错误:

{
  "stackTrace": [
    [
      "/var/task/processing.py",
      54,
      "lambda_handler",
      "KeyName=keyname, SubnetId='subnet-<>', SecurityGroupIds=['sg-<>'])"
    ],
    [
      "/var/runtime/boto3/resources/factory.py",
      520,
      "do_action",
      "response = action(self, *args, **kwargs)"
    ],
    [
      "/var/runtime/boto3/resources/action.py",
      83,
      "__call__",
      "response = getattr(parent.meta.client, operation_name)(**params)"
    ],
    [
      "/var/task/botocore/client.py",
      251,
      "_api_call",
      "return self._make_api_call(operation_name, kwargs)"
    ],
    [
      "/var/task/botocore/client.py",
      537,
      "_make_api_call",
      "raise ClientError(parsed_response, operation_name)"
    ]
  ],
  "errorType": "ClientError",
  "errorMessage": "An error occurred (RequestExpired) when calling the RunInstances operation: Request has expired."
}
Run Code Online (Sandbox Code Playgroud)

发生了什么事?很确定这不是代码错误,因为从早上起就一直在运行相同的代码。

python amazon-web-services boto3 aws-lambda

0
推荐指数
1
解决办法
5144
查看次数

对于日期,Geom rect填充不正常

geom_rectggplot2 存在问题.我想用浅蓝色遮挡vline左边的区域.但是,这很有趣.(也许是因为涉及的日期栏).

代码:

library(dplyr)
library(ggplot2)
library(scales)

df <- read.csv("~/Desktop/dataset.csv")

# df <- df[!duplicated(df$caseid),]

df$createdat <- as.numeric(as.character(df$createdat))
df$resolutionat <- as.numeric(as.character(df$resolutionat))



df <- df[df$resolutionat != 0,]

df <- mutate(df, age = (resolutionat - createdat))
df <- mutate(df, counts = assigneechangecount + teamchangecount)
df <- mutate(df, isbreached = rbinom(388, 1, 0.2))
df<- mutate(df, resolutiondate = as.POSIXct(df$resolutionat, origin="1970-01-01"))

xstart <- as.POSIXct("2016-04-26 20:36:21 IST")
xend <- as.POSIXct("2016-04-28 12:00:38 IST")


print(ggplot(df, aes(resolutiondate, age, size = counts, color = factor(isbreached))) +
             geom_point(alpha = 0.4) +
             geom_point(shape …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

-1
推荐指数
1
解决办法
1342
查看次数