尝试使用brython更新python脚本的结果时发生未捕获的错误

时间:2018-10-19 04:31:10

标签: brython

我是布莱顿的新手。尝试使用brython将python脚本的运行结果更新到我的页面时,我得到了uncaught error

Uncaught Error
    at Object._b_.AttributeError.$factory (eval at $make_exc (brython.js:7017), <anonymous>:31:340)
    at attr_error (brython.js:6184)
    at Object.$B.$getattr (brython.js:6269)
    at CallWikifier0 (eval at $B.loop (brython.js:4702), <anonymous>:34:66)
    at eval (eval at $B.loop (brython.js:4702), <anonymous>:111:153)
    at $B.loop (brython.js:4702)
    at $B.inImported (brython.js:4696)
    at $B.loop (brython.js:4708)
    at $B.inImported (brython.js:4696)
    at $B.loop (brython.js:4708)

这是我的页面

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<head>
<script src="/brython-3.7.0rc1/www/src/brython.js"></script>
<script src="/brython-3.7.0rc1/www/src/brython_stdlib.js"></script>
</head>

<body onload="brython()">
<script type="text/python" src="vttToWiki.py"></script>
<div class="wrap">title</div>
<p id="content-title"></p>
<div class="wrap">subtitle</div>
<div id="content-subtitle" class="content-div">
<p id="message" font-color=white>loading...</p> 
</div>
<button id="mybutton">click!</button>
</body>

</html>

这是我的python脚本。这是与http://www.wikifier.org/annotate-article的脚本联系,CallWikifier是一个用于语义注释的网站。给定文本,函数import sys, json, urllib.parse, urllib.request from browser import alert, document, html element = document.getElementById("content-title") def CallWikifier(text, lang="en", threshold=0.8): # Prepare the URL. data = urllib.parse.urlencode([ ("text", text), ("lang", lang), ("userKey", "trnwaxlgwchfgxqqnlfltzdfihiakr"), ("pageRankSqThreshold", "%g" % threshold), ("applyPageRankSqThreshold", "true"), ("nTopDfValuesToIgnore", "200"), ("nWordsToIgnoreFromList", "200"), ("wikiDataClasses", "true"), ("wikiDataClassIds", "false"), ("support", "true"), ("ranges", "false"), ("includeCosines", "false"), ("maxMentionEntropy", "3") ]) url = "http://www.wikifier.org/annotate-article" # Call the Wikifier and read the response. req = urllib.request.Request(url, data=data.encode("utf8"), method="POST") with urllib.request.urlopen(req, timeout = 60) as f: response = f.read() response = json.loads(response.decode("utf8")) # Save the response as a JSON file with open("record.json", "w") as f: json.dump(response, f) # update the annotations. for annotation in response["annotations"]: alert(annotation["title"]) elt = document.createElement("B") txt = document.createTextNode(f"{annotation}\n") elt.appendChild(txt) element.appendChild(elt) document["mybutton"].addEventListener("click", CallWikifier("foreign minister has said Damascus is ready " +"to offer a prisoner exchange with rebels.") 得到注释结果和相应的Wiki URL。

start cmd /C ""%Location%\b.bat" "Input Argument 1""

如果您对此有任何想法,请告诉我。谢谢您的指教!

0 个答案:

没有答案