簡體   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