'Check' object has no attribute 'image' while using sightengine api - python

I am using sightengine API to detect child sexual abuse in images. In order to do that I am trying to detect the nudity level in an image using sightengine API. The following example is provided in the documentation itself.
from sightengine.client import SightengineClient
client = SightengineClient('api_user', 'api_key')
output = client.check('nudity').image('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
Apart from copying the same code I am getting the following error.
Traceback (most recent call last):
File "driver.py", line 3, in <module>
output = client.check('nudity').image('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
AttributeError: 'Check' object has no attribute 'image'
I have used both Python 2 and Python 3 for the same code but both raise the same error.

Try This:
from sightengine.client import SightengineClient
client = SightengineClient('API user', 'API secret')
checkNudity = client.check('nudity')
output1 = checkNudity.set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
print(output1)

Related

tkintermapview PhotoImage object has no attribute '_PhotoImage__photo'

I am making a project based on tkintermapview, but it throws the error when the following code is run.
import tkintermapview as tkmap
self.map = tkmap.TkinterMapView(self.__map_frame, width=self.__map_width,
height=self.__height, corner_radius=0)
# google normal tile server
self.map.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
# google satellite tile server
# self.map.set_tile_server("https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
# self.map.set_tile_server("http://c.tile.stamen.com/watercolor/{z}/{x}/{y}.png") # painting style
self.map.pack(fill=tk.BOTH)
self.map.set_address("kathmandu")
if the last line i.e. set_address() is removed then it runs fine otherwise it throws the error.
following is the error message:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/ImageTk.py", line 118, in __del__
name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
Exception ignored in: <function PhotoImage.__del__ at 0x7fa9e10ed510>
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/ImageTk.py", line 118, in __del__
name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
Process finished with exit code 0
I tried the following code as well to reproduce the error
from tkintermapview import TkinterMapView
root_tk = tkinter.Tk()
root_tk.geometry(f"{600}x{400}")
root_tk.title("map_view_simple_example.py")
# create map widget
map_widget = TkinterMapView(root_tk, width=600, height=400, corner_radius=0)
map_widget.pack(fill="both", expand=True)
# google normal tile server
map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22)
map_widget.set_address("chyasal")
root_tk.mainloop()
But this time the error is shown for the first time only. After that the program works correctly.
But again when I change the place to new location say set_address("Manang") again for the first launch, the same error is occured.
But this is not the case with all the places, I tried many different places inside the set_address() method, but only some of them caused the error.
I have one more question
My project should enable a user to pick the pick up and drop off location on the map and the map should calculate the shortest road and its distance(length of road) between the two locations.
Is tkintermapview good choice or is there a better way to display google map and implement this requirement in tkinter...?

How to start a Plex stream using python-PlexAPI?

I'm making a python script using the module PlexAPI. My goal is to start a stream on the client Chrome. The movie to view has the key /library/metadata/1.
Documentation and sources of code:
playMedia documentation
Example 4 is used but changed to fit my requirements
I'm using the key parameter
from plexapi.server import PlexServer
baseurl = 'http://xxx.xxx.xxx.xxx:xxxxx'
token = 'xxxxx'
plex = PlexServer(baseurl, token)
client = plex.client("Chrome")
client.playMedia(key="/library/metadata/1")
This gives the following error:
Traceback (most recent call last):
File "start_stream.py", line 7, in <module>
client.playMedia(key="/library/metadata/1")
TypeError: playMedia() missing 1 required positional argument: 'media'
So I edit the file:
client.playMedia(key="/library/metadata/1")
#changed to
client.playMedia(key="/library/metadata/1", media="movie")
But then I get a different error:
Traceback (most recent call last):
File "start_stream.py", line 7, in <module>
client.playMedia(key="/library/metadata/1", media="movie")
File "/usr/local/lib/python3.8/dist-packages/plexapi/client.py", line 497, in playMedia
server_url = media._server._baseurl.split(':')
AttributeError: 'str' object has no attribute '_server'
I don't really understand what's going on. Can someone help?
I was able to make it work the following way:
from plexapi.server import PlexServer
baseurl = 'http://xxx.xxx.xxx.xxx:xxxxx'
token = 'xxxxx'
plex = PlexServer(baseurl, token)
key = '/library/metadata/1'
client = plex.client("Chrome")
media = plex.fetchItem(key)
client.playMedia(media)

Shodan - Python Syntax to use "Info" Tag

So I'm currently working on a script using Shodan in Python using import shodan.
The documentation around isn't the best so id thought I'd bring my issue here.
Using the Shodan CLI there is a command known as Shodan Info which displays the number of search credits that your account has remaining.
When looking at the Shodan Documentation i can see that there is an info() tag but whenever I use it there has been an error.
Does anyone know the correct syntax for using info in a python script to display the number of credits an account has?
Errors i have received:
ipinfo = shodan.info()
print (ipinfo)
Error
Traceback (most recent call last):
File "C:/Users/XXXX/OneDrive - XXXX/Documents/XX Documents/XXXX/Working
Segments/ShodanScraper.py", line 8, in <module>
ipinfo = shodan.info()
AttributeError: module 'shodan' has no attribute 'info'
And
ipinfo = shodan.Shodan(info())
print (ipinfo)
Error
Traceback (most recent call last):
File "C:/Users/XXXX/OneDrive - XXXX/Documents/XXXXDocuments/XXXXXX/Working
Segments/ShodanScraper.py", line 8, in <module>
ipinfo = shodan.Shodan(info())
NameError: name 'info' is not defined
You need to instantiate the Shodan class and then you will be able to use its Shodan.info() method. Here is how it looks in the official command-line interface:
https://github.com/achillean/shodan-python/blob/master/shodan/__main__.py#L364
Here's a short script that prints the current account usage information:
import pprint
import shodan
key = 'YOUR API KEY'
api = shodan.Shodan(key)
results = api.info()
pprint.pprint(results)
shodan does not express how to use info. heres a breif example of how to set up shodan info
import shodan
api = shodan.Shodan('YOUR API KEY')
info = api.host('8.8.8.8')
shodan info

Getting docker stats programmatically

I am using docker-py and trying to get docker stats. But I am unable to get any API for returning stats for particular container. Is there a REST API or any other way to programmatically get the stats ?
>>> cli = docker.Client(base_url="tcp://xxxxx:2375", version='1.21')
>>> cli.containers() >> gives the right o/p
>>> cli.containers.get()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'get'
>>> docker.version
'1.10.6'
You may be looking for Container.stats.
Get stats for a particular container name example: "monitoring-tinydb".
Note: change this container name with your desired container id or name.
import docker
client = docker.from_env()
container = client.containers.get("monitoring-tinydb")
status = container.stats(decode=None, stream = False)
print(status)
Get stats for all containers running in the docker host
import docker
client = docker.DockerClient(base_url='unix:///var/run/docker.sock')
for containers in client.containers.list():
print(containers.stats(decode=None, stream = False))

python webbrowser

I've been using this module without problems by calling it as:
webbrowser.open("http link...")
now, however, I wanted to select a different browser, and according to the docs (http://docs.python.org/library/webbrowser.html#webbrowser.get) I wrote this
controller = webbrowser.get('firefox')
controller("http link...")
... and I get an error I'm unable to get rid of:
Exception in Tkinter callback
Traceback (most recent call last):
....
TypeError: 'Mozilla' object is not callable
any idea about it???
A Controller object is not callable. Do this:
controller.open(url)

Categories