如何在python中使用urllib3获取json数据

SP1*_*037 2 json urllib3 python-3.x

我正在使用 python-urllib3 制作简单的 ip-info 提供程序,我应该如何将数据获取到

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)

Run Code Online (Sandbox Code Playgroud)

我收到这样的错误

json.decoder.JSONDecodeError:期望值:第1行第1列(字符0)

Mat*_*420 5

试试这个代码:

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)
Run Code Online (Sandbox Code Playgroud)