当我运行以下功能时:
def checkChange():
for user in userLinks:
url = userLinks[user]
response = urllib2.urlopen(url)
html = response.read()
我明白了
Traceback (most recent call last):
File "InStockBot.py", line 34, in <module>
checkChange()
File "InStockBot.py", line 24, in checkChange
html = response.read()
UnboundLocalError: local variable 'response' referenced before assignment
这对我来说毫无意义。我没有全局 var 响应。我希望它正常工作如下。
>>> url="http://google.com"
>>> response = urllib2.urlopen(url)
>>> html = response.read()
>>> html
'<!doctype html>
有谁知道我为什么会收到这个错误?