我正在构建一个基本文件服务器,我的程序找不到文件.
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) 我正在尝试使用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?
有没有办法将引号字符的混合存储为 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 的问题。
这非常有效:
awk '{for (i=1;i<=NF;i++) if($i ~/mystring/) print $1, $i}'
Run Code Online (Sandbox Code Playgroud)
但是我也希望在$ i字段之外打印第二个字段.
想法?