'how to get data in json using urllib3 in python

I am making simple ip-info provider using python-urllib3, how should i fetch data to values

import json
import urllib3

while True:
    ip=input("Enter Ip Address : ")
    url="https://ip-api.com/json/"
    http = urllib3.PoolManager()
    response=http.request('GET',url+ip)
    data=response.read()
    values=json.loads(data)

I am getting error like this

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)



Solution 1:[1]

Try this code:

import json
import urllib3

while True:
    ip = input("Enter Ip Address : ")
    url = "http://ip-api.com/json/"
    http = urllib3.PoolManager()
    response = http.request('GET', url + ip)
    data = response.data
    values = json.loads(data)
    print(values)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mathix420