httpsconnectionpool to extract the api



嗨,我正在尝试运行此代码,但它不工作,我得到这个错误消息

https://connectionpool (host='population.un.org', port=443):由于url:/dataportalapi/api/v1/locations/,重试次数超过了最大值(由ProxyError('Cannot connect to proxy. ')导致)', ConnectionResetError(10054, '已存在的连接被远程主机强制关闭',None, 10054, None)))


import pandas as pd
import json
import requests
# Declares the base URL for calling API
base_url = "https://population.un.org/dataportalapi/api/v1"
# Creates the target URL, indicators, in this instance
target = base_url + "/locations/"
# Calls the API
response = requests.get(target)
# Converts call into JSON
j = response.json()
# Converts JSON into a pandas DataFrame.
df = pd.json_normalize(j) # pd.json_normalize flattens the JSON to accomodate nested lists within the JSON structure
# Alternatively, a user can have the same results returned in a CSV format and import them directly using pandas.read_csv()
df2 = pd.read_csv(target+"?format=csv")
#To view response code:
print(response)
## <Response [200]>

我认为你的url_base包含一个错误。试着加上'。

base_url = "https://population.un.org/dataportalapi/api/v1.0">

相关内容

最新更新