首页 > 解决方案 > YELP API 代码应返回错误 401,但返回的是错误 400

问题描述

我目前正在学习 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]>

请让我知道您需要更多信息来帮助我。我在这里是一个完整的初学者并寻求帮助。

标签: pythonhttpvisual-studio-codeyelp-fusion-api

解决方案


根据 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)

推荐阅读