Python Sightengine (API) – ‘sightengine’ 没有 ‘Client’ 属性错误

huangapple go评论135阅读模式
英文:

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 &quot;C:\Users\Toni\Desktop\Redditvidscraper\redditvidscraper.py&quot;, line 14, in &lt;module&gt;
client = sightengine.Client(sightengine_user, sightengine_secret)
AttributeError: module &#39;sightengine&#39; has no attribute &#39;Client&#39;

This is my current code:

import sightengine
import os
import requests
import praw
import cv2
import subprocess


# Sightengine API credentials
sightengine_user = &quot;CENSORED&quot;
sightengine_secret = &quot;CENSORED&quot;

# Authenticate with Sightengine API
client = sightengine.Client(sightengine_user, sightengine_secret)


#SKIPPED CODE ----------------------------#

    
# Check if the video is shorter than 60 seconds
if duration &lt; 60:
    print(&quot;mp4_lenght=shorter-60s_[codecontinued]&quot;)

    # Apply workflow on the video
    workflow_id = &quot;CENSORED&quot;
    video_path = &quot;video.mp4&quot;
    response = client.check(&#39;workflow&#39;, workflow_id, video_path)
    print(&quot;started_for_searching_unwanted_content&quot;)

        # Check if the video contains unwanted content
    if response[&#39;status&#39;] == &#39;success&#39; and response[&#39;media&#39;][&#39;status&#39;] == &#39;success&#39;:
        if response[&#39;media&#39;][&#39;warnings&#39;]:
            print(&quot;mp4_content=unwanted&quot;)
        else:
            print(&quot;mp4_content=wanted&quot;)
    else:
        print(&quot;Error: &quot;, response[&#39;status&#39;])

else:
    print(&quot;mp4_lenght=longer-60s_[codestopped]&quot;)
    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(&#39;{api_user}&#39;, &#39;{api_secret}&#39;)

So in your case you would do this

from sightengine.client import SightengineClient
client = SightengineClient(sightengine_user, sightengine_secret)

huangapple
  • 本文由 发表于 2023年2月27日 04:06:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574714.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定