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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:49:27+00:00 2026-06-04T11:49:27+00:00

Traceback (most recent call last): File C:\Users\Penguin\workspace\geocode-nojansdatabase\src\geocode.py, line 15, in place, (lat, lng) =

  • 0

Traceback (most recent call last):
File “C:\Users\Penguin\workspace\geocode-nojansdatabase\src\geocode.py”, line 15, in
place, (lat, lng) = g.geocode(a)
File “C:\Python27\lib\site-packages\geopy-0.94.2-py2.7.egg\geopy\geocoders\google.py”, line 81, in geocode
return self.geocode_url(url, exactly_one)
File “C:\Python27\lib\site-packages\geopy-0.94.2-py2.7.egg\geopy\geocoders\google.py”, line 88, in geocode_url
return dispatch(page, exactly_one)
File “C:\Python27\lib\site-packages\geopy-0.94.2-py2.7.egg\geopy\geocoders\google.py”, line 111, in parse_xml
“(Found %d.)” % len(places))
ValueError: Didn’t find exactly one placemark! (Found 3.)

When geopy encounters an address that it does not like my application terminates. What I am wondering is how I can capture the exception in Python and allow my program to move on to the next entry. The source code is below:

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)
     place, (lat, lng) = g.geocode(a)
     b = "\"" + str(place) + "\"" + "," + str(lat) + "," + str(lng) + "\n"
     print b
     f.write(b)
  • 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-04T11:49:30+00:00Added an answer on June 4, 2026 at 11:49 am

    To make your program ignore the ValueError instead of terminating on it, catch the exception, by replacing:

     place, (lat, lng) = g.geocode(a)
    

    with:

     try:
         place, (lat, lng) = g.geocode(a)
     except ValueError:
         continue
    

    (the continue makes it go to the next repeat of the for loop, instead of trying to execute the rest of the current loop – that seems like the right thing to do, since the rest of the current loop depends on place, lat, lng).

    Or, if you want it to print a message, use

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

    Or something along those lines.

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

Sidebar

Related Questions

Traceback (most recent call last): File manage.py, line 10, in <module> execute_from_command_line(sys.argv) File D:\PythonPack\lib\site-packages\django\core\management\__init__.py,
Traceback (most recent call last): File <pyshell#9>, line 1, in <module> ClosestCommonAncestor(A,C,x) File C:\x\x.py,
>>> import MySQLdb Traceback (most recent call last): File <stdin>, line 1, in <module>
>>> import pylibmc Traceback (most recent call last): File <stdin>, line 1, in <module>
ho-fe3fdd00-12:~ Sam$ easy_install BeautifulSoup Traceback (most recent call last): File /usr/bin/easy_install, line 8, in
When error occured Python prints something like this: Traceback (most recent call last): File
Consider the following stacktrace: In [3]: f.clean() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last)
2009-06-30 23:36:28,483 ERROR appcfg.py:1272 An unexpected error occurred. Aborting. Traceback (most recent call last):
When I run python manage.py collectstatic , I get: Traceback (most recent call last):
Why am I getting no attribute __getitem__ error for dictionary: Traceback (most recent call

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.