使用python3导入boto3时发生属性错误

时间:2020-05-25 12:48:22

标签: python amazon-web-services boto3

我正在尝试在树莓派上使用boto3使用aw rekognition客户端,已成功安装aws cli并对其进行了配置。但是,当我在aws博客中执行以下代码avaialbe时,

import boto3

def detect_labels_local_file(photo):


    client=boto3.client('rekognition')

    with open(photo, 'rb') as image:
        response = client.detect_labels(Image={'Bytes': image.read()})

    print('Detected labels in ' + photo)    
    for label in response['Labels']:
        print (label['Name'] + ' : ' + str(label['Confidence']))

    return len(response['Labels'])

def main():
    photo='photo'

    label_count=detect_labels_local_file(photo)
    print("Labels detected: " + str(label_count))


if __name__ == "__main__":
    main()

我收到以下错误:

  import boto3
  File "/usr/local/lib/python3.7/dist-packages/boto3/__init__.py", line 16, in <module>
    from boto3.session import Session
  File "/usr/local/lib/python3.7/dist-packages/boto3/session.py", line 17, in <module>
    import botocore.session
  File "/home/pi/.local/lib/python3.7/site-packages/botocore/session.py", line 28, in <module>
    import botocore.configloader
  File "/home/pi/.local/lib/python3.7/site-packages/botocore/configloader.py", line 19, in <module>
    from botocore.compat import six
  File "/home/pi/.local/lib/python3.7/site-packages/botocore/compat.py", line 25, in <module>
    from botocore.exceptions import MD5UnavailableError
  File "/home/pi/.local/lib/python3.7/site-packages/botocore/exceptions.py", line 99, in <module>
    class SSLError(ConnectionError, requests.exceptions.SSLError):
AttributeError: module 'botocore.vendored.requests' has no attribute 'exceptions

请帮助我解决问题,或告诉我我做错了什么。注意:我使用的是python 3.7.3。

1 个答案:

答案 0 :(得分:1)

blog post应该有助于对其进行解释。

您现在需要自己包含此依赖项,因为它不再与boto3捆绑在一起。

对于您的Raspberry Pi,运行以下命令就足够了

pip install requests

然后将import requests添加到您的py脚本