【问题标题】:Kinesis python client drops any message with "\x" escape?Kinesis python 客户端丢弃任何带有“\x”转义的消息?
【发布时间】:2017-03-11 08:40:55
【问题描述】:

我正在使用 boto3(1.4.4 版)与 Amazon 的 Kinesis API 通信:

import boto3
kinesis = boto3.client('kinesis')

# write a record with data '\x08' to the test stream
response = kinesis.put_record(StreamName='test', Data=b'\x08', PartitionKey='foobar')
print(response['ResponseMetadata']['HTTPStatusCode']) # 200

# now read from the test stream
shard_it = kinesis.get_shard_iterator(StreamName="test", ShardId='shardId-000000000000', ShardIteratorType="LATEST")["ShardIterator"]
response = kinesis.get_records(ShardIterator=shard_it, Limit=10)
print(response['ResponseMetadata']['HTTPStatusCode']) # 200
print(response['Records']) # []

当我使用没有 \x 转义的任何数据对其进行测试时,我能够按预期取回记录。 Amazon boto3's doc 表示“数据块可以是任何类型的数据;例如,来自日志文件的片段、地理/位置数据、网站点击流数据等。”那么为什么带有\x 转义字符的消息会丢失?在将数据发送到 kinesis 之前,我需要 '\x08'.encode('string_escape') 吗?

如果您有兴趣,我在消息数据中有 \x08 之类的字符,因为我正在尝试将序列化的协议缓冲区消息写入 Kinesis 流。

【问题讨论】:

  • 您是说您的 Lambda 函数永远不会收到包含二进制数据的消息吗?
  • @garnaat 我没有使用任何 lambda 函数,我只是在写入流后使用 python kinesis 客户端从流中读取。我的意思是,尽管消息写入似乎成功,但当我从流中读取时,无论我在写入后等待多长时间,都没有记录。虽然我在没有\x转义的情况下写了一条消息后能够阅读记录。

标签: python python-2.7 protocol-buffers boto3 amazon-kinesis


【解决方案1】:

好吧,我终于想通了。它不起作用的原因是因为我的 botocore 版本为1.4.62。我之所以意识到这一点,是因为另一个在我同事的机器上运行良好的脚本在我的机器上抛出了异常。我们有相同的 boto3 版本,但不同的 botocore 版本。在我pip install botocore==1.5.26 另一个脚本和我的运动put_record 开始工作之后。

tldr:botocore 1.4.62 在很多方面都被严重破坏了,所以现在就升级吧。我无法相信过时的破图书馆浪费了我多少生命。我想知道亚马逊开发人员是否可以取消发布客户端的损坏版本?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    相关资源
    最近更新 更多