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

  • Home
  • SEARCH
  • 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 8888499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:03:30+00:00 2026-06-14T22:03:30+00:00

When I test my module in console no errors are given, but when I

  • 0

When I test my module in console no errors are given, but when I try to receive the data from a browser I get an error message:

UnboundLocalError: local variable 'mile' referenced before assignment

This is the relevant part of my code:

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()

I’m confused why I get this error only from the web browser.

Thanks

  • 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-14T22:03:31+00:00Added an answer on June 14, 2026 at 10:03 pm

    I was able to sort the error by declaring a global variable ‘mile’ and also by cleaning up the indentation (thanks for the suggestion @MartijnPieters). So I inserted a global variable here:

    while cursor.alive:
        try:
            doc = yield motor.Op(cursor.next_object)
            global mile
    
            if doc: ...............
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need py.test to log assert errors in log file from python logging module. The
I am getting this error when running some unit tests (using the Test::Unit module
I am using python unit test module. I am wondering is there anyway to
module Test def self.model_method puts this is a module method end end class A
When I test DAO module in JUnit, an obvious problem is: how to recover
scala> object Test defined module Test Why is the defined object Test called 'module',
I have a PowerShell module called Test.psm1. I want to set a value on
I`d like to know how I could unit-test the following module. def download_distribution(url, tempdir):
I need some like this: module One def test; puts 'Test One'; end end
when i run fabric-0.9.1 in cygwin, it say following error: $ fab test.py Traceback

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.