获取HTTPConnectionPool d

2024-10-02 00:34:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用一个开放式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}$

Tags: nonestreetnumbercityaddressstatuscodecontent
2条回答

您的数据实际上是由result.json()返回的。在

{cd2>你可能被额外的细节搞糊涂了。在

这可能表示result.json()具有自定义表示(如中所示,它实现__repr__或{}),并在打印时在后台附加该数据。在

使用请求。容易得多。pip install requests

然后:

import requests

ak_url="http://api.map.baidu.com/location/ip"
BAIDU_IPADDR_AK = 'test'
result = requests.get(ak_url,{"ip":"183.11.178.1","ak":BAIDU_IPADDR_AK})
print(result.json())

我得到的结果是:

^{pr2}$

相关问题 更多 >

    热门问题