使用Sightengine API时遇AttributeError:模块无Client属性
解决
AttributeError: module 'sightengine' has no attribute 'Client'错误 以下是针对你遇到的API调用问题的具体解决方案:
升级并确认Sightengine SDK版本
你的代码使用的是旧版SDK的调用逻辑,当前官方Python SDK已更新了核心类名。先执行命令确保安装最新版本:pip install --upgrade sightengine修正客户端初始化代码
替换原有导入和客户端创建逻辑:
原代码片段:import sightengine client = sightengine.Client(sightengine_user, sightengine_secret)修改为:
from sightengine.client import SightengineClient client = SightengineClient(sightengine_user, sightengine_secret)更新视频工作流检查调用方式
新版SDK中视频检查的方法已拆分,原client.check需替换为专门的视频工作流检查方法:
原代码片段:response = client.check('workflow', workflow_id, video_path)修改为:
response = client.video.check_workflow(workflow_id, video_path)排查同名文件冲突
检查项目目录下是否存在sightengine.py文件或同名文件夹,这会导致Python误导入本地文件而非官方SDK包。如果有,立即重命名该文件/文件夹。
修改后的完整代码片段示例:
from sightengine.client import SightengineClient import os import requests import praw import cv2 import subprocess # Sightengine API credentials sightengine_user = "CENSORED" sightengine_secret = "CENSORED" # Authenticate with Sightengine API client = SightengineClient(sightengine_user, sightengine_secret) #SKIPPED CODE ----------------------------# # Check if the video is shorter than 60 seconds if duration < 60: print("mp4_lenght=shorter-60s_[codecontinued]") # Apply workflow on the video workflow_id = "CENSORED" video_path = "video.mp4" response = client.video.check_workflow(workflow_id, video_path) print("started_for_searching_unwanted_content") # Check if the video contains unwanted content if response['status'] == 'success' and response['media']['status'] == 'success': if response['media']['warnings']: print("mp4_content=unwanted") else: print("mp4_content=wanted") else: print("Error: ", response['status']) else: print("mp4_lenght=longer-60s_[codestopped]") exit()
内容的提问来源于stack exchange,提问作者Toni Storm
相关产品推荐
相关产品推荐

