Boto3和Python3:无法将“字节”对象隐式转换为str

AgentX

我正在尝试使用AWS Rekognition,detect_text API。我正在将Boto3和Python 3一起使用。

这是我的相关代码:

with open(file_path, 'rb') as file:
  data = file.read()

response = self._rekognition.detect_text(Image={'Bytes': data})

该代码在Python2.7上有效,但在Python3上失败。我收到以下错误:

File "...", line 39, in extract_text
response = self._rekognition.detect_text(Image={'Bytes': data})
...
...
k_date = self._sign(('AWS4' + key).encode('utf-8'),
TypeError: Can't convert 'bytes' object to str implicitly

任何想法我需要在这里更改。

拉胡尔

在python 3中,您可能需要将字节转换为str使用。

data.decode('utf-8')

或者您可以将文本文件作为文本本身读取。

尝试:

with open(file_path, encoding='utf-8') as file:
  data = file.read()
response = self._rekognition.detect_text(Image={'Bytes': data})

我不知道_rekognition.detect接受什么,但是您可以尝试。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python3错误:TypeError:无法将“字节”对象隐式转换为str

python3无法将字节隐式转换为对象'str'

无法将“字节”对象隐式转换为str

无法将'nonetype'对象隐式转换为str-Python3

无法将'int'对象隐式转换为str:Python 3+

在python3中将dict的键和值从“字节”转换为“ str”的最快方法

TypeError:无法将“ int”对象隐式转换为str

TypeError:无法将“ int”对象隐式转换为str

TypeError:无法将“列表”对象隐式转换为str

TypeError:无法将“节点”对象隐式转换为str

“无法将'float'对象转换为隐式str“

TypeError:无法将“模块”对象隐式转换为str

Swig无法将python3的字节对象转换为std :: string

python gettext错误:无法将'__proxy__'对象隐式转换为str

Python:TypeError:无法将“生成器”对象隐式转换为str

无法在python 3.4.3中将'int'对象隐式转换为str

“无法将'int'对象隐式转换为str”错误(Python)

Python 错误:写入 json 文件时无法将“列表”对象隐式转换为 str

无法将“ int”对象隐式转换为str。Python错误

TypeError:无法将'int'对象转换为str隐式错误python

TypeError:无法将'int'对象隐式转换为str(python)

TypeError:无法将“ float”对象隐式转换为str或TypeError:-:“ str”和“ float”的不受支持的操作数类型

TypeError-无法将“用户”对象隐式转换为str

Tensorflow TypeError:无法将'numpy.int64'对象转换为隐式str

awscli 错误 - 无法将“NoneType”对象隐式转换为 str

TypeError:无法将“ builtin_function_or_method”对象隐式转换为str

TypeError:使用套接字时无法将“ bytes”对象转换为隐式str

Masonite-TypeError:无法将“未定义”对象隐式转换为str

TypeError:对于Pascode系统,无法将“ int”对象隐式转换为str