Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:29:34+00:00 2026-06-17T09:29:34+00:00

When I run the following function: def checkChange(): for user in userLinks: url =

  • 0

When I run the following function:

def checkChange():
    for user in userLinks:
        url = userLinks[user]
        response = urllib2.urlopen(url)  
        html = response.read()

I get

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

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

>>> url="http://google.com"
>>> response = urllib2.urlopen(url)  
>>> html = response.read()
>>> html
'<!doctype html>

Anyone know why I get this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:29:35+00:00Added an answer on June 17, 2026 at 9:29 am

    You’re mixing tabs and spaces. Looking at the raw code you pasted:

    '    def checkChange():'
    '    \tfor user in userLinks:'
    '    \t\turl = userLinks[user]'
    '    \t\tresponse = urllib2.urlopen(url)  '
    '            html = response.read()'
    

    You can see the switch in the last line. Effectively, this means that the html = response.read() line isn’t indented as far as you think it is, meaning that if userLinks is empty, you’ll get:

    Traceback (most recent call last):
      File "inde.py", line 10, in <module>
        checkChange()
      File "inde.py", line 5, in checkChange
        html = response.read()
    UnboundLocalError: local variable 'response' referenced before assignment
    

    Run your code using python -tt yourprogramname.py to confirm this, and switch to always using four-space tabs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following function: def f(): if TESTING: # Run expensive
When I try to run this view/function, I get the following error execute() first
I have the following function that I only want to run inside <div id=imgWrapper>
I have written the following function but it's isn't returning anything when I run
Help me translate following block of the Haskell code. The run function produces text
What is the check_union256d function? It's placed in following code: /* { dg-do run
Suppose I have following code: def foo(s): A dummy function foo. For example: >>>
I have a simple script with user defined function run that I want to
I have the following python function that allows me to run shell commands from
When I run the following sample: def a(): exec('import math') b() def b(): print

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.