簡體   English   中英

使用python3導入boto3時出現屬性錯誤

[英]Attribute error while importing boto3 using python3

我正在嘗試在我的樹莓派上使用 boto3 使用 aws rekognition 客戶端,已成功安裝 aws cli 並對其進行了配置。 但是當我在 aws 博客中執行以下代碼時,

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。

這篇博文應該有助於解釋它。

您現在需要自己包含此依賴項,因為它不再與 boto3 捆綁在一起。

對於運行以下內容的 Raspberry Pi 來說應該足夠了

pip install requests

然后將import requests添加到您的 py 腳本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM