我对Anvil服务器在服务器、上行链路和客户端之间的身份验证和通信方面的工作方式并不十分熟悉。但是,我会尽可能多地解释这个问题,请原谅我的英语:
1-我在anvil online editor上创建了一个简单的“Hello World”应用程序,然后我对它进行了测试,它工作得非常好
2-我使用外部上行链路功能将服务器脚本保存在远程服务器上,所有内容都像一个符咒一样工作,下面是代码:
from ._anvil_designer import Form1Template
from anvil import *
import anvil.server
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
self.message_label.text = anvil.server.call('get_name', self.name_box.text)
pass
def text_box_3_pressed_enter(self, **event_args):
"""This method is called when the user presses Enter in this text box"""
pass
def sum_click(self, **event_args):
"""This method is called when the button is clicked"""
self.result.text = anvil.server.call('add_nums', self.num1.text, self.num2.text)
pass
下面是在外部上行链路上运行的服务器脚本:
import anvil.server
anvil.server.connect("UPLINK DERIVED FROM ANVIL ONLINE")
@anvil.server.callable
def get_name(name):
response = "Hello from the server, %s!" % name
return response
@anvil.server.callable
def add_nums(num1,num2):
result = int(num1)+int(num2)
return result
anvil.server.wait_forever()
3-现在,我尝试通过git克隆Anvil online上的应用程序,以便完全从外部服务器托管它:
git clone ssh://bla@bla.bla@anvil.works:2222/RN35GHXNR4UHW77W.git Hello_World
anvil-app-server --app Hello_World --origin https://somewhere.domain.com
到目前为止,该应用程序通过外部URL在浏览器上正常加载
4-最后,当我输入一些数据并按下按钮时,我最终出现了这个丑陋的错误:
[ERROR anvil.app-server.run] Error report from client code:
NoServerFunctionError: No server function matching "get_name" has been registered
Traceback:
app/Hello_World/Form1/__init__.py:15
^CTraceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/melsayeh/env/lib/python3.8/site-packages/anvil_downlink_host/run.py", line 4, in <module>
anvil_downlink_host.run_downlink_host()
File "/home/melsayeh/env/lib/python3.8/site-packages/anvil_downlink_host/__init__.py", line 474, in run_downlink_host
time.sleep(5)
当您在本地启动应用程序服务器时,需要传递要用于该应用程序的上行密钥
然后,您需要在上行脚本中向connect调用添加相同的密钥。您还需要在该调用中传递指向应用服务器的URL参数
您可以在以下位置查看应用程序服务器的选项,包括上行密钥:
https://github.com/anvil-works/anvil-runtime#advanced-configuration
相关问题 更多 >
编程相关推荐