我已经构建了一个关键字研究应用程序,它在本地服务器上成功运行,但是当我将它部署到 extends Node2D
export var SOCKET_URL = "ws://127.0.0.1:3333"
var _client = WebSocketClient.new()
func _ready():
_client.connect("connection_closed", self, "_on_connection_closed")
_client.connect("connection_error", self, "_on_connection_closed")
_client.connect("connection_established", self, "_on_connected")
_client.connect("data_received", self, "_on_data")
var err = _client.connect_to_url(SOCKET_URL)
if err != OK:
print('unable to connect')
set_process(false)
func _process(delta):
_client.poll()
func _on_connection_closed(was_clean = false):
print('Closed, clean: %s' % was_clean)
set_process(false)
func _on_connected(proto = ''):
print('connected with protocol: %s' % proto)
func _on_data():
var payload = JSON.parse(_client.get_peer(1).get_packet().get_string_from_utf8()).result
print('received data: %s' % payload)
func _send():
_client.get_peer(1).put_packet(JSON.print({"test": "Test"}).to_utf8())
时,它抛出了一个错误:
UnboundLocalError:赋值前引用了局部变量“插入”:
我该如何解决这个问题?
这是我的代码:
Cpanel
任何建议将不胜感激。
谢谢。
答案 0 :(得分:0)
问题可能来自这里:
for tag in meta:
if 'name' in tag.attrs.keys() and tag.attrs['name'].strip().lower() in ['keywords']:
insert = tag.attrs['content']
print(insert)
data = insert.split(',')
这里:
for tag in meta:
if 'name' in tag.attrs.keys() and tag.attrs['name'].strip().lower() in ['keywords']:
insert1 = tag.attrs['content']
print(insert1)
data1 = insert1.split(',')
如果条件不成立,可能会发生插入未初始化的情况。您可以通过在 for 循环之前初始化 insert
来解决此问题。
insert = "" # some default value that works
for tag in meta:
if 'name' in tag.attrs.keys() and tag.attrs['name'].strip().lower() in ['keywords']:
insert = tag.attrs['content']
print(insert)
data = insert.split(',')
另一个:
insert = "" # some default value that works
for tag in meta:
if 'name' in tag.attrs.keys() and tag.attrs['name'].strip().lower() in ['keywords']:
insert1 = tag.attrs['content']
print(insert1)
data1 = insert1.split(',')