Power BI调用Police UK犯罪数据API时出现404 NOT FOUND错误求助
解决Power BI调用Police UK犯罪数据API返回404的问题
可能的原因及修复步骤
1. 确认日期参数的有效性
Police UK的API要求date参数必须是已结束的完整月份(当前月份因数据延迟不会开放查询)。你使用的2017-01格式合规,但可先测试一个更近的、确定有数据的月份(比如2023-12),替换后构造新请求URL:
https://data.police.uk/api/crimes-street/all-crime?lat=52.629729&lng=-1.131592&date=2023-12
2. 修正Power BI的请求配置
Power BI的Web.Contents函数可能因默认请求头或重定向逻辑导致404,可通过自定义Power Query调整:
- 选择「获取数据→空白查询」
- 打开高级编辑器,替换原有代码为:
let url = "https://data.police.uk/api/crimes-street/all-crime?lat=52.629729&lng=-1.131592&date=2023-12", options = [ Headers = [ #"User-Agent" = "PowerBI/1.0", #"Accept" = "application/json" ], FollowRedirects = true ], response = Web.Contents(url, options), json = Json.Document(response) in json
- 点击「关闭并应用」验证结果
3. 检查坐标点的可用数据
部分坐标点在指定月份可能无犯罪记录,API会直接返回404而非空数组:
- 先在浏览器中直接访问请求URL,确认是否能返回JSON数据
- 若浏览器也返回404,尝试更换城市中心区域的坐标,或调整查询月份
4. 避免URL编码错误
Power BI可能自动转义URL中的特殊字符(如负号-),可手动拆分参数构造URL:
let baseUrl = "https://data.police.uk/api/crimes-street/all-crime", params = [ lat = 52.629729, lng = -1.131592, date = "2023-12" ], fullUrl = baseUrl & "?" & Uri.BuildQueryString(params), response = Web.Contents(fullUrl), json = Json.Document(response) in json
内容的提问来源于stack exchange,提问作者user8216057
相关产品推荐
相关产品推荐

