python - 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]>
请让我知道您需要更多信息来帮助我。我在这里是一个完整的初学者并寻求帮助。
解决方案
根据 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)
推荐阅读
- javascript - Javascript 日期对象:startDate < nowDate 逻辑由于客户端上的时区差异而无法正常工作
- socket.io - 在sails 中响应socket.io post 函数的正确方法是什么?
- sveltekit - 在 SvelteKit 中全局导入图像 url
- python - 'str' 对象没有属性 'text'| 美丽汤
- php - 从 PHP 运行 node.js 脚本时无法访问文件
- c++ - 模板化检查是否存在类成员函数模板特化?
- python - 诱变剂问题无法使用字典中的信息
- git - 使用启动脚本克隆私有 Github 存储库?
- amazon-cognito - AWS Cognito:您应该为 UID 创建自定义属性吗?
- asp.net-core - EF Core 不会按顺序创建子实体