0

I am trying to extract city name from a text but it is giving an error. Here is my code:

import geograpy

text = 'I am from Delhi'

places = geograpy.get_place_context(text=text)

print(places.cities)

ERROR:

Traceback (most recent call last):

  File "C:/Users/M.B.C. Kadawatha/PycharmProjects/NewsFeed/NLP.py", line 17, in <module>
    places = geograpy.get_place_context(text=text)

  File "C:\Users\M.B.C. Kadawatha\PycharmProjects\NewsFeed\venv\lib\site-packages\geograpy\__init__.py", line 11, in get_place_context
    pc.set_cities()

  File "C:\Users\M.B.C. Kadawatha\PycharmProjects\NewsFeed\venv\lib\site-packages\geograpy\places.py", line 137, in set_cities
    self.populate_db()
  File "C:\Users\M.B.C. Kadawatha\PycharmProjects\NewsFeed\venv\lib\site-packages\geograpy\places.py", line 30, in populate_db
    for row in reader:
  File "C:\Users\M.B.C. Kadawatha\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 274: character maps to <undefined>
num3ri
  • 822
  • 16
  • 20
  • I install geograpy through `python3 -m pip install git+https://github.com/reach2ashish/geograpy.git` and your code can be run successfully. – keineahnung2345 Feb 16 '19 at 00:24
  • I used this command pip3 -m pip install git+https://github.com/reach2ashish/geograpy.git But when I ran that command, The result would be : Usage: pip [options] no such option: -m – Rasindu De Alwis Feb 16 '19 at 02:51
  • It's `python3 -m`, not `pip3 -m`. – keineahnung2345 Feb 16 '19 at 02:56
  • @keineahnung2345 It is giving this error that why I decided to use pip3 'python3' is not recognized as an internal or external command, operable program or batch file. – Rasindu De Alwis Feb 16 '19 at 03:38
  • or just use `pip install git+https://github.com/reach2ashish/geograpy.git` – keineahnung2345 Feb 16 '19 at 03:39
  • Still getting this error :- return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 274: character maps to – Rasindu De Alwis Feb 16 '19 at 03:55
  • Possible duplicate of [UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to ](https://stackoverflow.com/questions/9233027/unicodedecodeerror-charmap-codec-cant-decode-byte-x-in-position-y-character) – Sociopath Feb 16 '19 at 04:08
  • @AkshayNevrekar what is the file name in here and where to put this file = open(filename, encoding="utf8") – Rasindu De Alwis Feb 16 '19 at 05:07
  • Try adding `#!/usr/bin/python3`, `# -*- coding: utf-8 -*-`(two lines) in the start of your python script file. – keineahnung2345 Feb 16 '19 at 05:35
  • @keineahnung2345 getting this error:- return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 274: character maps to – Rasindu De Alwis Feb 16 '19 at 05:58

1 Answers1

0

This should be a bug in the package geograpy.

In geograpy/places.py, revise:

with open(cur_dir+"/data/GeoLite2-City-Locations.csv", "rb") as info:

to

with open(cur_dir+"/data/GeoLite2-City-Locations.csv", "r", encoding="utf-8") as info:

And the problem of encoding should go away.

keineahnung2345
  • 2,635
  • 4
  • 13
  • 28