【问题标题】:Here.com API proper structureHere.com API 正确结构
【发布时间】:2020-02-19 01:04:53
【问题描述】:

当我运行这段代码时:

url = f"https://traffic.ls.hereapi.com//traffic/6.3/incidents.json?proximity=37.3541,-121.9552?apiKey={api_key}"

Scrape Here.com for any traffic incidents in the last 24 hours for the set proximity
res = requests.get(url)
date_requested = time.strftime('%Y-%m-%d')
time_requested = time.strftime('%H:%M')
date_requested; time_requested #print date & time of request

我得到这个错误:

<html><body><p>{"error":"Unauthorized","error_description":"ApiKey is missing."}</p></body></html>

谁能告诉我为什么?我知道 API 密钥是有效的,因为我生成了一个新密钥并将其剪切并粘贴到上面的代码中,所以它必须是我查询的结构,不是吗?

我非常感谢任何和所有的帮助。

【问题讨论】:

    标签: here-api


    【解决方案1】:

    问题出在您的 URL 部分 替换第二个?与 & 如下-

    url = f"https://traffic.ls.hereapi.com//traffic/6.3/incidents.json?proximity=37.3541,-121.9552&apiKey={}"
    

    【讨论】:

    • 我们使用 & 运算符来拆分请求中的各种参数。
    • 您只能使用一个“?” URL 中的符号。后面的一切都是参数,它们应该用符号“&”连接起来。要了解有关构建正确 URL 的更多信息,请参阅此维基百科文章:en.wikipedia.org/wiki/URL
    猜你喜欢
    • 1970-01-01
    • 2021-01-09
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 2015-03-21
    • 2017-07-24
    相关资源
    最近更新 更多