小编sch*_*der的帖子

Python path.exists()返回False

我正在构建一个基本文件服务器,我的程序找不到文件.

def sendfile(sock, myfile):
    print 'Serving file:', myfile
    print 'File exists?:', os.path.exists(myfile)

    path = os.path.normpath(os.path.join(os.getcwd(), myfile))
    print 'Serving file:', path
    print 'File exists?:', os.path.exists(path)
Run Code Online (Sandbox Code Playgroud)

即使'myfile'和'path'正确[文件与服务器程序位于同一目录],它们总是返回False.

IDLE工作正常,但没有传递给函数.

>>> print os.path.exists("/user/server/foo.txt")  
True
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

[编辑:]输出:

Serving file: foo.txt

File exists?: False
Serving file: /user/server/foo.txt

File exists?: False
Run Code Online (Sandbox Code Playgroud)

python file

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

如何使用boto3 authorize_security_group_ingress在非默认VPC中的两个安全组之间添加规则

我正在尝试使用boto3更新安全组规则,将规则添加到安全组a(sg_a)以允许安全组b(sg_b)访问端口8443.

我正在尝试使用EC2客户端来实现以下功能

ec2.authorize_security_group_ingress(
        GroupId=sg_a,
        SourceSecurityGroupName=sg_b,
        IpProtocol='tcp',
        FromPort=service_port,
        ToPort=service_port
    )
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误:

botocore.exceptions.ClientError: An error occurred (VPCIdNotSpecified) when calling the AuthorizeSecurityGroupIngress operation: No default VPC for this user.
Run Code Online (Sandbox Code Playgroud)

如何将authorize_security_group_igress用于非默认VPC?

amazon-ec2 aws-cli boto3

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

在Redis中存储html并保留引号

有没有办法将引号字符的混合存储为 Redis 中的值?我的具体需求是存储 PHP 和 HTML 字符串,并保持引用类型的混合。

在Python中:

import redis
db = redis.Redis('localhost')

phpfile = /root/test.php

with open(phpfile) as f:
    bar = f.read()

db.set('foo', bar)
Run Code Online (Sandbox Code Playgroud)

如果我尝试以任何其他直接方式传递字符串,它当然会失败,因为所有竞争的引号。

编辑:

我要结束这个问题。我无法使用上面的代码在 Python 中重复该行为,因此这一定是我代码中另一层的问题,而不是 Redis 的问题。

python redis

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

awk - 打印一个远离匹配字段的字段n个字段

这非常有效:

awk '{for (i=1;i<=NF;i++) if($i ~/mystring/) print $1, $i}'
Run Code Online (Sandbox Code Playgroud)

但是我也希望在$ i字段之外打印第二个字段.

想法?

awk

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

标签 统计

python ×2

amazon-ec2 ×1

awk ×1

aws-cli ×1

boto3 ×1

file ×1

redis ×1