gpt4 book ai didi

Python.Runtime.PythonException : since Python. NET 3.0 int 无法隐式转换为 Enum。使用枚举(int_value)

转载 作者:行者123 更新时间:2023-12-05 05:36:49 30 4
gpt4 key购买 nike

我最近将我的代码移到了工作中的一台新电脑上。一个基本的示例代码如下(但您将无法运行它,因为您无法连接到我的服务器 - 抱歉,我无法使其更可重现)。

使用新电脑时,出现以下错误:

System.ArgumentException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value) in method OSIsoft.AF.Asset.AFValue RecordedValue(OSIsoft.AF.Time.AFTime, OSIsoft.AF.Data.AFRetrievalMode) ---> Python.Runtime.PythonException: since Python.NET 3.0 int can not be converted to Enum implicitly. Use Enum(int_value)*".

我的旧电脑使用 Spyder 4 和 Python 3.7 以及 Python.NET 2.5.2。新计算机使用 Spyder 5 和 Python 3.9 以及 Python.NET 3.0。由于IT限制,我无法在我的电脑上安装相同版本的Spyder和Python。但是,我不认为这是导致此错误的原因。

谁知道什么会导致枚举相关问题?谢谢!

import PIconnect as PI

def pidownload(tag):
with PI.PIServer() as server:
point = server.search(tag)[0]
data = point.recorded_value('-1m')
data=data.to_frame()
return data
tag='xxxx.pv' #confidential data tag replaced with xxxx
print(pidownload(tag))

screenshot of the error

最佳答案

根据 OSIsoft's documentationRecordedValue 函数的文档判断和 PIConnect documentationrecorded_value 的文档,似乎 Python 端函数正在发送一个枚举,而 C# 端函数正在接收一个枚举值。但是,在检查 GitHub documentation 时对于 PIConnect,我们可以看到问题出在 retrieval_mode 变量上,它的默认值为 RetrievalMode.AUTO,它是一个 IntEnum .似乎转换工作不正常,正如我注意到的 GitHub issue在他们的存储库上。

编辑

经过进一步检查,您的问题似乎是安装问题,可以通过重新安装 piconnect 来解决,参见 question .

关于Python.Runtime.PythonException : since Python. NET 3.0 int 无法隐式转换为 Enum。使用枚举(int_value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73252397/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com