Python - Weird UnboundLocalError
<p>When I run the following function:</p>

<pre><code>def checkChange():
    for user in userLinks:
        url = userLinks[user]
        response = urllib2.urlopen(url)  
        html = response.read()
</code></pre>

<p>I get </p>

<pre><code>Traceback (most recent call last):
  File "InStockBot.py", line 34, in &lt;module&gt;
    checkChange()
  File "InStockBot.py", line 24, in checkChange
    html = response.read()
UnboundLocalError: local variable 'response' referenced before assignment
</code></pre>

<p>Which makes no sense to me. I have no global var response. I expect it to work as below, normally.</p>

<pre><code>&gt;&gt;&gt; url="http://google.com"
&gt;&gt;&gt; response = urllib2.urlopen(url)  
&gt;&gt;&gt; html = response.read()
&gt;&gt;&gt; html
'&lt;!doctype html&gt;
</code></pre>

<p>Anyone know why I get this error?</p>
