Can't pickle <class 'pywintypes.datetime'>: attribute lookup datetime on pywintypes failed

我的梦境 提交于 2021-02-18 17:49:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!