gpt4 book ai didi

python - Geograpy3 库无法正常工作并给出回溯错误

转载 作者:行者123 更新时间:2023-12-04 17:38:43 26 4
gpt4 key购买 nike

我只是尝试使用 geograpy3 库从文本中提取位置。但它会引发错误。

enter image description here

for content in feedContent:

if content != "":
place = geograpy.get_place_context(text=content)
placesInFeed.append(place.places)

else:
placesInFeed.append("null")

结果是

Traceback (most recent call last):
File "C:/Users/Peshala/Documents/SDGP/Location-based-news-recommendation-master/Backend/rss_scraper.py", line 46, in <module>
place = geograpy.get_place_context(text=content)
File "C:\Users\Peshala\PycharmProjects\Location-based-news-recommendation\venv\lib\site-packages\geograpy\__init__.py", line 11, in get_place_context
pc.set_cities()
File "C:\Users\Peshala\PycharmProjects\Location-based-news-recommendation\venv\lib\site-packages\geograpy\places.py", line 137, in set_cities
self.populate_db()
File "C:\Users\Peshala\PycharmProjects\Location-based-news-recommendation\venv\lib\site-packages\geograpy\places.py", line 30, in populate_db
for row in reader:
File "C:\Users\Peshala\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 277: character maps to <undefined>

最佳答案

作为 geograpy3 的提交者,为了重现您的问题,我向最新的 geograpy3 添加了一个测试 https://github.com/somnathrakshit/geograpy3/blob/master/tests/test_extractor.py :

    def testStackoverflow55548116(self):
'''
see https://stackoverflow.com/questions/55548116/geograpy3-library-is-not-working-properly-and-give-traceback-error
'''
feedContent=['Las Vegas is a city in Nevada']
placesInFeed=[]

for content in feedContent:
if content != "":
e=Extractor(text=content)
e.find_entities()
places = e.places
if self.debug:
print(places)
placesInFeed.append(places)

结果可能不是你所期望的:

['Las', 'Vegas', 'Nevada']

但测试未显示任何错误,因此请提供显示错误的 feedContent - 您可能想要 fork 项目并修改测试并为您的问题添加拉取请求。

关于python - Geograpy3 库无法正常工作并给出回溯错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55548116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com