问题
I am using python 3.5 (32bit), win10-64bit, OpenOPC, and I have downloaded pywin32 build 64bit. I have run the following python code:
import OpenOPC
import time
opc=OpenOPC.client()
opc.connect('Matrikon.OPC.Simulation.1')
tags =['Random.Int4','Random.Real4']
while True:
try:
value = opc.read(tags,group='Group0',update=1)
print (value)
except OpenOPC.TimeoutError:
print ("TimeoutError occured")
time.sleep(5)
but I always get this error message:
Traceback (most recent call last): File "C:\Program Files (x86)\Python35-32\lib\multiprocessing\queues.py", line 241, in _feed obj = ForkingPickler.dumps(obj) File "C:\Program Files (x86)\Python35-32\lib\multiprocessing\reduction.py", line 50, in dumps cls(buf, protocol).dump(obj) _pickle.PicklingError: Can't pickle : attribute lookup datetime on pywintypes failed.
回答1:
I have found a solution:
import OpenOPC
import time
import pywintypes
pywintypes.datetime = pywintypes.TimeType
opc=OpenOPC.client()
opc.servers()
opc.connect('Matrikon.OPC.Simulation.1')
tags =['Random.Int1','Random.Real4','Random.Int2','Random.Real8']
while True:
try:
value = opc.read(tags,group='Group0',update=1)
print (value)
except OpenOPC.TimeoutError:
print ("TimeoutError occured")
time.sleep(1)
来源:https://stackoverflow.com/questions/54683823/cant-pickle-class-pywintypes-datetime-attribute-lookup-datetime-on-pywinty