B
B
beduin012017-10-04 09:03:48
Python
beduin01, 2017-10-04 09:03:48

How to convert GeoIP data class to JSON?

It is necessary to pull out the full JSON with data from the https://dev.maxmind.com/ database .
Now everything looks like this:
reader = geoip2.database.Reader(str(DBFullPath), "r")
response = reader.country(tempIP)
print(response)
As a result, I get something like this on the console:

geoip2.models.Country({'traits': {'ip_address': '8.35.60.229'}, u'country': {u'geoname_id': 6252001, u'iso_code': u'US', u'names': {u'ru': u'\u0421\u0428\u0410', u'fr': u'\xc9tats-Unis', u'en': u'United States', u'de': u'USA', u'zh-CN': u'\u7f8e\u56fd', u'pt-BR': u'Estados Unidos', u'ja': u'\u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd', u'es': u'Estados Unidos'}}, u'continent': {u'geoname_id': 6255149, u'code': u'NA', u'names': {u'ru': u'\u0421\u0435\u0432\u0435\u0440\u043d\u0430\u044f \u0410\u043c\u0435\u0440\u0438\u043a\u0430', u'fr': u'Am\xe9rique du Nord', u'en': u'North America', u'de': u'Nordamerika', u'zh-CN': u'\u5317\u7f8e\u6d32', u'pt-BR': u'Am\xe9rica do Norte', u'ja': u'\u5317\u30a2\u30e1\u30ea\u30ab', u'es': u'Norteam\xe9rica'}}, u'registered_country': {u'geoname_id': 6252001, u'iso_code': u'US', u'names': {u'ru': u'\u0421\u0428\u0410', u'fr': u'\xc9tats-Unis', u'en': u'United States', u'de': u'USA', u'zh-CN': u'\u7f8e\u56fd', u'pt-BR': u'Estados Unidos', u'ja': u'\u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd', u'es': u'Estados Unidos'}}}, r)

This is very similar to JSON. But not it. How can I get a full fledged JSOn?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2017-10-04
@fox_12

json.dumps
json.loads

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question