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)
Related
I am trying to the following code:
#!/usr/bin/python
import multiprocessing
def f(name):
print 'hello', name
if __name__ == '__main__':
p = multiprocessing.Process(target=f, args=('bob',))
p.start()
p.join()
The output I get is :
Traceback (most recent call last):
File "a.py", line 9, in <module>
p = multiprocessing.Process(target=f, args=('bob',))
AttributeError: 'module' object has no attribute 'Process'
You are trying to import multiprocessing from your local directory and not from the python library. The python interpreter first tries to import the module from the present directory. As you have got a file with the name multiprocessing.pyc in your directory, the interpreter is trying to import that. Hence you have got the error. Thus deleting multiprocessing.pyc will help resolve your problem.
Dont give the name of the file as "multiprocessing.py", give any other
thanks,
vybhav
The mistake was naming, my script as 'multiprocessing.py', once it was created. I made an another script with name 'a.py' and both of them were not working. After listing the directories, 'multiprocessing.pyc' was located. I deleted this file, and executed 'a.py' file which executed like gem!
thanks to #Bhargav Rao for highlighting
Don't give the name in the same directory as multiprocess.py, use different name instead.
I'd experienced weird result when testing couchbase python SDK.
below is the source code and result:
# xxx.py
from gcouchbase.bucket import Bucket
dsn = 'couchbase://[url-of-couchbase]/[bucket-name]'
db = Bucket(dsn)
# yyy.py
import logbook
import git
from xxx import db
# python yyy.py
Traceback (most recent call last):
File "/home/username/env/local/lib/python2.7/site-packages/gcouchbase/iops_gevent10.py", line 88, in timer_event_factory
return GEventTimer()
TypeError: 'NoneType' object is not callable
[1] 8546 abort (core dumped) python yyy.py
The weird thing is, when I remove import git or import logbook from yyy.py, the error doesn't happen.
Is there any reason for this error? should any resource for couchdb be disposed?
An asynchronous event seems to arrive after the Bucket object has been removed. If you call bucket._close() explicitly, the script would not be crashed. Anyways, it looks like a bug of gcouchbase.
recently i have created this topic and did not get the answer.
after that i edited this and added 2 screenshots.
right now i tested another temporary email library and got the same error :((
this library :
pip install python-guerrillamail
code python 2.7:
from guerrillamail import GuerrillaMailSession
session = GuerrillaMailSession()
print session.get_session_state()['email_address']
print session.get_email_list()[0].guid
it seemed i cant never work like this email lib.
updated after remove email.pyc:
Traceback (most recent call last):
File "C:\Users\11\Desktop\untitle.py", line 1, in <module>
from guerrillamail import Guerrillamail
ImportError: cannot import name Guerrillamail
Your module email.py, is shadowing, or hiding, the email package in Python's standard library. This is causing the error: in the traceback you can see that an error is being reported when the statement import email is executed.
Rename your file to something else, for example myemail.py.
I changed the code to " from guerrillamail import * " that is worked. this code seems import all things to program, maybe it causes to be heavy and executing time.
thanks to #snakecharmerb .
I must be doing something wrong that I can't figure out from other resources on teh web.
At one point in my script I try to run:
username= win32security.LookupAccountSid(None, ace[2])[0]
From which I get and error
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
win32security.LookupAccountSid(None, ace[2])[0]
error: (1332, 'LookupAccountSid', 'No mapping between account names and security IDs was done.')
I figured out this happens when you have a security registry for which there no longer is a user so it shows up on the permissions as S-1-xxx...
In order to get the script to move on I wrote:
try:
username= win32security.LookupAccountSid(None, ace[2])[0]
except:
nouser +=1
This code will still give the error and stop my script. How can I get my script to ignore when this error happens?
For this problem (stackoverflow.com/questions/4086435/), I tried to make a Python 3 version of the library python-websocket (github.com/mtah/python-websocket/), here is my code: https://gist.github.com/663175.
Blender comes with his own Python 3.1 package, so I added my file directly in its «site-packages» folder. I get this error now:
Traceback (most recent call last):
File "websocket.py", line 6, in
AttributeError: 'module' object has no attribute 'WebSocket'
when running this code in Blender:
import sys, os, asyncore, websocket
def msg_handler(msg):
print(msg)
socket = websocket.WebSocket('ws://localhost:8080/', onmessage=msg_handler)
socket.onopen = lambda: socket.send('Hello world!')
try:
asyncore.loop()
except KeyboardInterrupt:
socket.close()
I found that a __init__.py is needed so I added but it didn't help…
What I am doing wrong here ? Thanks for your help.
It looks like you called your script websocket.py, so the import of websocket finds the script itself, instead of the installed module by that name. Rename the script to something else (and if it created a websocket.pyc file, delete that.)