3

我是一名网络工程师,对编程很陌生,所以如果我遗漏了任何细节,请告诉我。尽我所能在这里解释这个问题 :)解决这个问题对我来说非常重要,所以任何输入都将受到高度赞赏

问题陈述: 我写了一个python脚本,它被一个brython脚本使用(在像javascript一样的html中使用,在编译时转换为javascript)。基本上,当我单击网页上的按钮时,它会触发我在 html 中提到的 python 脚本,如下所示:

*<body onload="brython()">
<script type="text/python" src="ip_tools.py"></script>*

python 脚本如下所示:

from browser import document as doc, bind
import ipaddress
def subcalc(ev):
    #Using the ipaddress module I get the ip_network, so the value ip will be like 192.168.1.0/24 (an object of ipaddress class)
    ip = ipaddress.ip_network(doc['ipadd'].value + '/' + doc['ipv4_mask'].value, strict=False)

    #This line gives the aforementioned error in Chrome Console
    *print(ip.hostmask)*

doc["sub_cal"].bind("click", subcalc)  #This line triggers the subcalc function when user clicks on a button with id-"sub_cal" on the webpage.

Chrome 控制台的完整错误:

error in get.apply Error
    at _b_.TypeError.$factory (eval at $make_exc (brython.js:7647), <anonymous>:161:327)
    at __get__491 (eval at exec_module (brython.js:8991), <anonymous>:5898:62)
    at __BRYTHON__.builtins.object.object.__getattribute__ (brython.js:5332)
    at Object.$B.$getattr (brython.js:6731)
    at subcalc0 (eval at $B.loop (brython.js:5230), <anonymous>:120:48)
    at HTMLButtonElement.<anonymous> (brython.js:12784) brython.js:5334 get attr hostmask of Object brython.js:5335 function () { [native code] } brython.js:6108 Traceback (most recent call last): TypeError: Cannot use cached_property instance without calling __set_name__ on it.

我有类似的脚本工作正常,唯一的区别是该脚本使用导入的 Python 库其他脚本不使用此类库,除了浏览器库(Brython 需要它来处理 html 内容)

4

1 回答 1

2

感谢您报告此问题,这是 Brython 中 PEP 487 实施中的一个错误。它已在此提交中修复。

于 2019-12-14T18:31:48.707 回答