【问题标题】:YELP API code expected to return error 401, but instead error 400 is returnedYELP API 代码应返回错误 401,但返回的是错误 400
【发布时间】:2020-09-06 00:46:34
【问题描述】:

我目前正在学习 YELP API,并希望执行业务搜索,但我遇到了错误 400(HTTP 400 - 错误请求)。按照在线课程,我的代码(在虚拟环境中运行)应该返回错误 401(HTTP 401)(然后我们提供创建的 yelp 应用程序 ID 和密钥等),但我收到错误 400 并且找不到解决方法这个,所以我得到错误 401 并且可以继续......

这是我的代码,它非常简单,我检查了语法错误但找不到。我正在寻找几个小时的答案,然后真的开始迷失自我了......有人可以帮我吗?

import requests

response = requests.get("https://api.yelp.com/v3/businesses/search") # to send GET (to read) request to an endpoint.
print(response)

运行代码时的结果:

<Response [400]>

请让我知道您需要什么更多信息来帮助我。我是这里的初学者,正在寻求帮助。

【问题讨论】:

    标签: python http visual-studio-code yelp-fusion-api


    【解决方案1】:

    根据 Yelp 文档,您需要包含 (1) 位置或 (2) 纬度和经度的查询参数。您的请求似乎缺少这些参数。

    https://www.yelp.com/developers/documentation/v3/business_search

    请看下面的例子:

    import requests
    
    response = requests.get("https://api.yelp.com/v3/businesses/search?latitude=37.786882&longitude=-122.399972") # to send GET (to read) request to an endpoint.
    print(response)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-05
      • 2019-07-12
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 2017-02-17
      • 2021-12-18
      • 2016-03-16
      相关资源
      最近更新 更多