英文:
Python Sightengine (API) - 'sightengine' has no attribute 'Client' Error
问题
我目前正在编写一个Reddit网页抓取器的代码。我希望在下载的视频中使用Sightengine来扫描不适当的内容。我在与API通信方面遇到了问题(无法完全描述),但我卡在了这个cmd输出上:
```none
File "C:\Users\Toni\Desktop\Redditvidscraper\redditvidscraper.py", line 14, in <module>
client = sightengine.Client(sightengine_user, sightengine_secret)
AttributeError: module 'sightengine' has no attribute 'Client'
这是我的当前代码:
import sightengine
import os
import requests
import praw
import cv2
import subprocess
# Sightengine API凭证
sightengine_user = "CENSORED"
sightengine_secret = "CENSORED"
# 使用Sightengine API进行身份验证
client = sightengine.Client(sightengine_user, sightengine_secret)
# SKIPPED CODE ----------------------------#
# 检查视频是否短于60秒
if duration < 60:
print("mp4_lenght=shorter-60s_[codecontinued]")
# 在视频上应用工作流程
workflow_id = "CENSORED"
video_path = "video.mp4"
response = client.check('workflow', workflow_id, video_path)
print("started_for_searching_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()
我尝试了虚拟环境,更新各种软件包,下载和设置SSL,就我所知,这段代码没有逻辑或语法错误,只是与这个API的通信有问题。
<details>
<summary>英文:</summary>
I am currently writing the code for an reddit scraper. I wanted to use Sightengine for scanning for inappropriate content within the downloaded videos. I have problems communicating with the api (I cant fully describe it), however - this is the cmd output that I cant fix and am stuck at:
```none
File "C:\Users\Toni\Desktop\Redditvidscraper\redditvidscraper.py", line 14, in <module>
client = sightengine.Client(sightengine_user, sightengine_secret)
AttributeError: module 'sightengine' has no attribute 'Client'
This is my current code:
import sightengine
import os
import requests
import praw
import cv2
import subprocess
# Sightengine API credentials
sightengine_user = "CENSORED"
sightengine_secret = "CENSORED"
# Authenticate with Sightengine API
client = sightengine.Client(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.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()
I tried virtual environments, updating all kind of packages, downloading + setting up SSL and as far as I am concerned this code has no logical or syntax errors its just the communication with this api.
答案1
得分: 0
在sightengine的GitHub存储库中提到,要初始化客户端,应该这样做:
from sightengine.client import SightengineClient
client = SightengineClient('{api_user}', '{api_secret}')
所以在你的情况下,你应该这样做:
from sightengine.client import SightengineClient
client = SightengineClient(sightengine_user, sightengine_secret)
英文:
In the github repository for sightengine it says that you should do this to initialize the client:
from sightengine.client import SightengineClient
client = SightengineClient('{api_user}', '{api_secret}')
So in your case you would do this
from sightengine.client import SightengineClient
client = SightengineClient(sightengine_user, sightengine_secret)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论