繁体   English   中英

使用geograpy(Python)从文本中提取城市时出现错误

[英]Giving an error when extracting cities from a text using geograpy(Python)

我正在尝试从文本中提取城市名称,但出现错误。 这是我的代码:

import geograpy

text = 'I am from Delhi'

places = geograpy.get_place_context(text=text)

print(places.cities)

错误:

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>

这应该是geograpy包中的geograpy

geograpy/places.py ,修改:

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

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

并且编码问题应该消失了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM