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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:32:23+00:00 2026-05-13T16:32:23+00:00

I have csv file having some address data mostly in Finnish language. I need

  • 0

I have csv file having some address data mostly in Finnish language. I need to read that file and getting some geocode information of these address. But It doesn’t work for Finnish alphabet and says it cant read those! Can anybody please help me out of this?

import urllib,urllib2,time

addr_file = 'address.csv'
out_file = 'addresses_geocoded.csv'
out_file_failed = 'failed.csv'
sleep_time = 2
root_url = "http://maps.google.com/maps/geo?"
gkey = "asfasdfasdfasdf"       # not an actual value
return_codes = {'200':'SUCCESS',
                         '400':'BAD REQUEST',
                         '500':'SERVER ERROR',
                         '601':'MISSING QUERY',
                         '602':'UNKOWN ADDRESS',
                         '603':'UNAVAILABLE ADDRESS',
                         '604':'UNKOWN DIRECTIONS',
                         '610':'BAD KEY',
                         '620':'TOO MANY QUERIES'

                         }
def geocode_for_musiquitous(addr_file,out_fmt='csv'):
        #encode our dictionary of url parameters
        values = {'q' : addr_file, 'output':out_fmt, 'key':gkey}
        data = urllib.urlencode(values)
        #set up our request
        url = root_url+data
        req = urllib2.Request(url)
        #make request and read response
        response = urllib2.urlopen(req)
        geodat = response.read().split(',')
        response.close()

        # this section is just handle the data returned from google
        code = return_codes[geodat[0]]
        if code == 'SUCCESS':
                code,precision,lat,lng = geodat
                return {'code':code,'precision':precision,'lat':lat,'lng':lng}
        else:
                return {'code':code}

def main():
#open  i/o files
        outf = open(out_file,'w')
        outf_failed = open(out_file_failed,'w')
        inf = open(addr_file,'r')
        for address in inf:
            #get latitude and longitude of address
                data = geocode_for_musiquitous(address)


            #output results and log to file



                if len(data)>1:
                        print "Latitude and Longitude of "+address+":"
                        print "\tLatitude:",data['lat']
                        print "\tLongitude:",data['lng']
                        outf.write(address.strip()+data['lat']+','+data['lng']+'\n')
                        outf.flush()
                else:
                        print "Geocoding of '"+addr_file+"' failed with error code "+data['code']
                        outf_failed.write(address)


                        outf_failed.flush()

                time.sleep(sleep_time)

                #clean up
        inf.close()
        outf.close()
        outf_failed.close()

if __name__ == "__main__":
        main()
  • 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-05-13T16:32:23+00:00Added an answer on May 13, 2026 at 4:32 pm

    The argument of urllib.url should be UTF-8 encoded beforehand:

    addr_file = addr_file.encode("utf-8")
    values = {'q' : addr_file, 'output':out_fmt, 'key':gkey}
    data = urllib.urlencode(values)
    

    And make sure you open the CSV file with the correct encoding (might be “windows-1252” or “iso-8859-1”):

    inf = codecs.open(addr_file, 'r', 'iso-8859-1')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.