geoip

Geoip2's python library doesn't work in pySpark's map function

Geoip2's python library doesn't work in pySpark's map function Question: I’m using geoip2’s python library and pySpark to get the geographical address of some IPs. My code is like: geoDBpath = ‘somePath/geoDB/GeoLite2-City.mmdb’ geoPath = os.path.join(geoDBpath) sc.addFile(geoPath) reader = geoip2.database.Reader(SparkFiles.get(geoPath)) def ip2city(ip): try: city = reader.city(ip).city.name except: city = ‘not found’ return city I tried print …

Total answers: 2