Geograpy3库无法正常工作,并提供回溯错误

时间:2019-04-06 10:21:02

标签: python python-3.6 geography

我只是尝试使用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>

1 个答案:

答案 0 :(得分:1)

作为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-您可能希望分叉项目并修改测试,并为您的问题添加请求请求。