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 8005379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:12:51+00:00 2026-06-04T17:12:51+00:00

I have some Python code with error handling in place but for some reason

  • 0

I have some Python code with error handling in place but for some reason the code still seems to be unable to handle this particular error:

raise GQueryError("No corresponding geographic location could be found for the     specified location, possibly because the address is relatively new, or because it may be incorrect.")
geopy.geocoders.google.GQueryError: No corresponding geographic location could be found for the specified location, possibly because the address is relatively new, or because it may be incorrect.

This is the source:

import csv
from geopy import geocoders
import time

g = geocoders.Google()

spamReader = csv.reader(open('locations.csv', 'rb'), delimiter='\t', quotechar='|')

f = open("output.txt",'w')

for row in spamReader:
    a = ', '.join(row)
    #exactly_one = False
    time.sleep(1)

    try:
        place, (lat, lng) = g.geocode(a)
    except ValueError:
        #print("Error: geocode failed on input %s with message %s"%(a, error_message))
        continue 

    b = str(place) + "," + str(lat) + "," + str(lng) + "\n"
    print b
    f.write(b)

Have I not included enough error handling? I was under the impression that “except ValueError” would handle this situation but I must be wrong on that.

Thanks in advance for any help out!

P.S. I pulled this out of the code but I don’t know what it really means yet:

   def check_status_code(self,status_code):
    if status_code == 400:
        raise GeocoderResultError("Bad request (Server returned status 400)")
    elif status_code == 500:
        raise GeocoderResultError("Unkown error (Server returned status 500)")
    elif status_code == 601:
        raise GQueryError("An empty lookup was performed")
    elif status_code == 602:
        raise GQueryError("No corresponding geographic location could be found for the specified location, possibly because the address is relatively new, or because it may be incorrect.")
    elif status_code == 603:
        raise GQueryError("The geocode for the given location could be returned due to legal or contractual reasons")
    elif status_code == 610:
        raise GBadKeyError("The api_key is either invalid or does not match the domain for which it was given.")
    elif status_code == 620:
        raise GTooManyQueriesError("The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time.")
  • 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-04T17:12:54+00:00Added an answer on June 4, 2026 at 5:12 pm

    Right now the try/except is only catching ValueErrors. To catch GQueryError as well, replace the except ValueError: line with:

    except (ValueError, GQueryError):
    

    Or if GQueryError isn’t in your namespace, you may need something like this:

    except (ValueError, geocoders.google.GQueryError):
    

    Or to catch ValueError and all the errors listed in check_status_code:

    except (ValueError, GQueryError, GeocoderResultError, 
            GBadKeyError, GTooManyQueriesError):
    

    (Again, add geocoders.google. or whatever the error location is to the front of all the geopy errors if they’re not in your namespace.)

    Or, if you just want to catch all possible exceptions, you could simply do:

    except:
    

    but this is generally bad practice, because it’ll also catch things like a syntax error in your place, (lat, lng) = g.geocode(a) line, which you don’t want caught, so it’s better to examine the geopy code to find all the possible exceptions it could be throwing that you want to catch. Hopefully all of those are listed in that bit of code you found.

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

Sidebar

Related Questions

I have a python ndarray temp in some code I'm reading that suffers this:
I have some python code which runs every 10 minutes or so. It reads
I have some python code which generates a 256^3 numpy array of data that
I have some Python code that works as expected if I type the commands
I have created some python code which creates an object in a loop, and
I have some really nice Python code to do what I need to do.
I have an SGE script to execute some python code, submitted to the queue
We have some code written in python that uses a few classes that are
I have some code in a python string that contains extraneous empty lines. I
I have some python code for Google App Engine that responds with the string

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.