我使用一个开放式API,使用其访问密钥获取以下信息:
HTTPConnectionPool(host='freeipapi.17mon.cn', port=80): Max retries exceeded with url: /183.11.178.118 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x103780780>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
{'status': 0, 'address': 'CN|广东|深圳|None|CHINANET|0|0', 'content': {'address_detail': {'province': '广东省', 'city_code': 340, 'street': '', 'city': '深圳市', 'district': '', 'street_number': ''}, 'address': '广东省深圳市', 'point': {'x': '12693451.44', 'y': '2560682.35'}}}
你看,后面的数据{'status': 0, 'address': 'CN|广东|深圳|None|CHINANET|0|0', 'content': {'address_detail': {'province': '广东省', 'city_code': 340, 'street': '', 'city': '深圳市', 'district': '', 'street_number': ''}, 'address': '广东省深圳市', 'point': {'x': '12693451.44', 'y': '2560682.35'}}}
是我的需要。在
我怎样才能得到它?在
代码如下:
^{pr2}$
您的数据实际上是由
result.json()
返回的。在{cd2>你可能被额外的细节搞糊涂了。在
这可能表示}),并在打印时在后台附加该数据。在
result.json()
具有自定义表示(如中所示,它实现__repr__
或{使用请求。容易得多。
pip install requests
然后:
我得到的结果是:
^{pr2}$相关问题 更多 >
编程相关推荐