我正在尝试使用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] 删除。
我来说两句