I am working on a Raspberry Pi 3 and I am trying to visualize some values of sensors on Munin. I am using Python in order to execute scripts on Munin.
I found a script to test and I am trying to execute it but I got the following error :
Traceback (most recent call last):
File "cpu_field", line 23, in
munin.main()
AttributeError: 'module' object has no attribute
'main'
This is the script : https://github.com/CooledCoffee/python-munin/
Of course, I added at the beginning :
!/usr/bin/env python
But, what I didn't understand is that others scripts are working like this one :
https://gist.github.com/tomoconnor/813813
Would be nice if you could put the code in the question as well.
Anyways. The python-munin you use is entirely different and provides no main() function (as it called in line 23). Names for python modules are not protected and
'munin' is a obvious choice used by more than one developer.
The first script should run with the module you get with
pip install python-munin
The other script uses this python-munin module and you probably get it directly from the git repository. They are not compatible.
So, this is the code I am using :
> #!/usr/bin/env python
>
> import munin
>
> category = 'system' fields = [
> 'load1',
> 'load5',
> 'load15', ] vlabel = 'load'
>
> def values():
> with open('/proc/loadavg') as f:
> data = f.read()
> load1, load5, load15 = [float(s) for s in data.split()[:3]]
> return {
> 'load1': load1,
> 'load5': load5,
> 'load15': load15,
> }
>
> if __name__ == '__main__':
> munin.main()
This is the answer I got with sudo python xxx, I got the same answer with sudo munin-run xxx :
pi#dex:/etc/munin/plugins $ sudo python first
Traceback (most recent call last):
File "first", line 24, in <module>
munin.main()
AttributeError: 'module' object has no attribute 'main'
I thin you are right because when I installed munin with
pip install python-munin
it worked. But, then I installed this python-munin module and it didn't work anymore. I removed the folder python-munin but I still got the same error.
How can I remove properly the previous folder ?
Related
I'm new to Python and I want to run the Duplex tool (https://github.com/beurtschipper/Depix ). But the test version does not start, when I type an in the command line:
python depix.py -p images/testimages/testimage3_pixels.png -s images/searchimages/debruinseq_notepad_Windows10_closeAndSpaced.png -o output.png
an error occurs:
Traceback (most recent call last):
File "F:\Work\Projects\Python\Depix\Depix-main\depixlib\depix.py ", line 10, in <module>
from. import __version__
Error Importer error: an attempt at relative import without a known parent package
In the READMI written
sh
depix \
-p /path/to/your/input/image.png \
-s images/searchimages/debruinseq_notepad_Windows10_closeAndSpaced.png \
-o /path/to/your/output.png
But I do not know how to run it, please help
I had the same error and it looks like it is a directory structure problem.
You can fix it by adding depixlib where you import the modules.
depixlib\depix.py
from depixlib import __version__
from depixlib.functions import
from depixlib.LoadedImage import LoadedImage
from depixlib.Rectangle import Rectangle
Hope it fixed your problem!
Now, I get the following errors, but that's another story. 😅
LoadedImage.py
return cast(list[list[tuple[int, int, int]]], _imageData)
TypeError: 'type' object is not subscriptable
edit: Actually I fixed the above by changing the following line to:
Last line of LoadedImage.py file
return cast(list(list([int, int, int])), _imageData)
It was mentionned here: https://github.com/beurtschipper/Depix/pull/83
Cheers!
I am trying to move data (a dint specifically but my example is a BOOL) from the plc to python to be used as a variable to display a picture. The issue is, if I use pycomm, I am getting an error in Windows Powershell. I feel this is a very simple error from a basic python mistake rather than a pycomm issue but I am not informed enough to tell.
SysInfo:
configparser==3.5.0
cpppo==3.9.7
greenery==2.1
ipaddress==1.0.18
pycomm==1.0.8
pyreadline==2.1
pytz==2017.2
python==2.7.13
Code I am using:
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
if __name__ == '__main__':
c = ClxDriver()
if c.open('IPADDRESSHERE'):
print(c.read_tag(['new_Bool']))
c.close()
Which is just a stripped down version of one of the examples on github https://github.com/ruscito/pycomm
This is the result from running powershell:
PS C:\Users\Tom\Documents\PythonProjects> python pycomm2.py
Traceback (most recent call last):
File "pycomm2.py", line 10, in
print(c.read_tag(['new_Bool']))
File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag
self.logger.warning(self._status)
AttributeError: 'Driver' object has no attribute 'logger'
PS C:\Users\Tom\Documents\PythonProjects>
I have looked for this AttributeError and tried to find a solution, but I think the solutions I have found are over my head. If I have failed to provide some details in order for this question to make sense please let me know.
Edit:
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
if __name__ == '__main__':
logging.basicConfig(
filename="ClxDriver.log",
format="%(levelname)-10s %(asctime)s %(message)s",
level=logging.DEBUG
)
c = ClxDriver()
if c.open('IPADRESSHERE'):
print(c.read_tag(['new_Bool']))
c.close()
Yields the same attribute error.
PS C:\Users\Tom\Documents\PythonProjects> python pycommtest.py
Traceback (most recent call last):
File "pycommtest.py", line 15, in
print(c.read_tag(['new_Bool']))
File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag
self.logger.warning(self._status)
AttributeError: 'Driver' object has no attribute 'logger'
PS C:\Users\Tom\Documents\PythonProjects>
I was able to read a value, but not with pycomm. Using CPPPO, I was able to continuously update a variable as needed. This may not answer the question of what was wrong with my old code, but it is my work around in case someone from the future has to do the same thing. Credit to user Liverpool_chris and the abyss of Reddit.
https://www.reddit.com/r/PLC/comments/5x3y5z/python_cpppo_library_writing_to_tag_in_plc/
from cpppo.server.enip.get_attribute import proxy_simple
import time
host = "IPHERE"
while True:
x, = proxy_simple(host).read(( "CPID"))
print x
time.sleep(5)
I installed scapy for python3.4 as suggested to me in previous post (link: https://github.com/phaethon/scapy).
I tried to run this very simple code to show all the wifi networks detected by the program:
#!/usr/bin/python3.4
from scapy import *
ap_list = []
def PacketHandler(pkt) :
if pkt.haslayer(Dot11) :
if pkt.type == 0 and pkt.subtype == 8 :
if pkt.addr2 not in ap_list :
ap_list.append(pkt.addr2)
print ("AP MAC: {} with SSID: {} ".format(pkt.addr2, pkt.info))
sniff(iface="mon0", prn = PacketHandler)
I get the following error when I run the script:
python3.4 test_scapy.py
Traceback (most recent call last):
File "test_scapy.py", line 16, in <module>
sniff(iface="mon0", prn = PacketHandler)
NameError: name 'sniff' is not defined
It seems to me that the function 'sniff' does not work just as in the previous versions, I tried to find the problem without success. If someone knows how to make the function 'sniff' work on this version it would help me a lot.
Thank you for your time.
I have a python script like this:
#!/usr/bin/env python
from scapy.all import *
from ospf import *
def ourSend(packet):
sendp(packet,iface='eth1')
host1='10.0.3.2'
advr_routers='10.0.8.7'
host2='10.0.2.2'
sequence=0x80000918
link2host1 = OSPF_Link(id=host1,data='10.0.3.1',type=2,metric=1)
link2host2 = OSPF_Link(id=host2,data='10.0.2.2',type=2,metric=1)
link2victim = OSPF_Link(id="192.168.200.20",data="255.255.255.255",type=3,metric=1)
IPlayer=IP(src='10.0.1.2',dst='224.0.0.5')
OSPFHdr=OSPF_Hdr(src='10.0.6.1')
rogueLsa=Ether()/IPlayer/OSPFHdr/OSPF_LSUpd(lsacount=1,lsalist=[OSPF_Router_LSA(options=0x22,id='10.0.3.1',adrouter=advr_routers,seq=sequence,\
linkcount=3,linklist=[link2victim,link2host1,link2host2])])
ourSend(rogueLsa)
When I run it it has an scapy error.. So I resolved it with git pyrt...
now when I want to run the python script I have other error:
$ python scipt.py
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
File "s.py", line 19, in <module>
link2host1 = OSPF_Link(id=host1,data='10.0.3.1',type=2,metric=1)
NameError: name 'OSPF_Link' is not defined
Thank you
I Should separately get ospf.py again and run my script.
This is what I tried and worked...
When you git pyrt The module OSPF_Link can't be added. SO I used the ospf.py again and problem is solved now....
Earlier my code was working fine, suddenly while running my Python script:
**from neo4jrestclient.client import GraphDatabase
from bottle import route, run,template,post,request,redirect
gdb = GraphDatabase("http://localhost:7474/db/data/")*
#route('/home')
def open_home():
username=""
parties=[]
return template('home',dict(username=username,parties=parties))
This error shows up:
Traceback (most recent call last): > File "bottle3.py", line 4, in > gdb = > GraphDatabase("localhost:7474/db/data/") File > "/usr/local/lib/python2.7/dist-packages/neo4jrestclient/client.py", > > line 78, in init > raise NotFoundError(response.status_code, "Unable get root") neo4jrestclient.exceptions.NotFoundError: Code > [411]: Length Required. > Client must specify Content-Length.. Unable > get root
Have you removed all nodes in the database?
Have you upgraded to Neo4j >=2.0? With the release of 2.0.0 RC1 the database no longer contains a default node 0 (reference node), previously known as root.
I can recommend neo4jdb-python for an up to date python driver.