S3 的 BOTO 在尝试复制现有密钥时返回 NoSuchKey
我已经在 S3 上创建了一个密钥。
mykey.exists()
返回 true
mykey.get_contents_to_filename()
生成一个正确的文件
但是:
mykey.copy('bucket ', '/backup/file')
返回: NoSuchKey 指定的键不存在。 Key = mykey
看起来我正在使用 boto 2.0b4 如果密钥存在,为什么我会收到 NoSuchKey
错误? 我缺少什么?
编辑:将键名中的反斜杠更改为我实际使用的前斜杠
I've create a key on S3.
mykey.exists()
returns true
mykey.get_contents_to_filename()
generates a file that is correct
But:
mykey.copy('bucket', '/backup/file')
returns:NoSuchKey
The Specified key does not exist.
Key = mykey
It looks like I'm using boto 2.0b4
If the key exists, why am I getting a NoSuchKey
error?
What am I missing?
edit: change backslash in key name to the foreslashes that I am actually using
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一个理论,因为亚马逊 s3 最终是一致的,一个请求可以看到密钥 (.exists() == True),而另一个请求最终到达另一台 s3 服务器,该服务器尚不知道新密钥(不一致读取 - 这是最终一致的数据存储的困难。这是 s3 的已知行为,我希望它也能用于复制。)通常很短(但不确定)一段时间后。所有请求都会看到您的 钥匙。通常这只需要大约一两秒。在代码中的exists() 检查和复制之间设置 30 秒的超时。现在还会发生吗?
此处描述了该问题:https://forums.aws.amazon .com/thread.jspa?threadID=21634&tstart=0)
I have a theory that because amazon s3 is eventually consistent, one request could see the key (.exists() == True) while another request ends up at a different s3 server which does not yet have knowledge of the new key (an inconsistent read - this is the difficulty with eventually consistent data stores. This is known behavior for s3 with a put followed by a head/get. I expect it to hold for copy as well.) After a usually short (but indefinite) period of time all requests will see your key. Normally this is only about a second or two. Put a 30 second timeout in your code between the exists() check and the copy. Does it still happen?
The issue is described here: https://forums.aws.amazon.com/thread.jspa?threadID=21634&tstart=0)
我认为您的密钥名称可能遇到问题。字符串 '\backup\file' 中的 baskslash 字符实际上被解释为字符串转义符,因此 '\b' 被替换为 ASCII 退格字符,而 '\f' 被解释为 ASCII 换页符(请参阅 此 了解更多详细信息)。虽然这可能不是您想要的,但它确实应该仍然可以工作,但是 boto2.0b4 中的键名转义存在一个错误(现已在 github master 中修复),这导致了它无法工作。
如果您确实希望键名是“\backup\file”,请尝试在 Python 中将其指定为 r'\backup\file'。这会将其视为原始字符串,并且不会发生转义处理。
I think you may be running into an issue with your key name. The baskslash characters in the string '\backup\file' are actually is interpreted as string escapes so '\b' is replaced with the ASCII backspace character and '\f' is interpreted as the ASCII formfeed (see this for more details). While that probably isn't what you intended, it really should still work but there was a bug in the escaping of key names in boto2.0b4 (which is fixed now in github master) that is preventing this from working.
If you actually want your keyname to be "\backup\file" try specifying it as r'\backup\file' in Python. This treats it as a raw string and no escape processing will occur.