-1
将数据发送到Web浏览器当我测试模块中的控制台给出没有错误,但是当我尝试从一个浏览器我得到一个错误信息接收数据:错误蟒蛇
UnboundLocalError: local variable 'mile' referenced before assignment
这是我的代码相关部分:
while cursor.alive:
try:
doc = yield motor.Op(cursor.next_object)
if doc:
mileInfo={'time': doc['time_normal']}
print doc['term']
if doc['term'] == 'abc':
event = 'abc'
elif doc['term'] == 'def':
event = 'def'
elif doc['term'] == 'xyz':
event = 'xyz'
else:
event = 'rst'
if not doc['coordinates']:
placeName = doc['place']['full_name']
mile = from_name(placeName, event)
print 'from Name: ' ,mile, 'term: ', event, doc['place']['full_name']
else:
mile = get_coords(doc['coordinates']['coordinates'], event)
print 'from coordinates: ',mile, 'term: ', event, 'location:', doc['coordinates']['coordinates']
mileInfo['miles'] = mile
self.write_message(json.dumps(mileInfo, default = json_util.default))
except StopIteration:
pass
except:
traceback.print_exc()
我很困惑,为什么我只能从网络浏览器得到这个错误。
感谢
您的缩进是可怕的;这可能是你的问题的原因。 –
@MartijnPieters我很惊讶它运行。对于这些内容的编译会不会失败? – Ian
感谢您的回复。缩进是从我的工作区复制代码。我认为它被改变了。这是我得到的唯一回溯。 – user94628