python - Python 3.6 发布请求域 API
问题描述
这有点像新手Q。
我正在使用 Python 3.6
我正在尝试使用域房地产 api编写一个收集器来收集我所在地区待售房屋/公寓的数据,但我无法让发布请求正常工作。我已经注册并检索了我的 client_id 和 secret_id 以进行身份验证。发布请求返回 400 的 status_code
response = requests.post('https://auth.domain.com.au/v1/connect/token',
data = {'client_id':client_id,
"client_secret":client_secret,
"grant_type":"client_credentials",
"scope":"api_agencies_read api_listings_read",
"Content-Type":"application/json"})
token=response.json()
access_token=token["access_token"]
search_parameters = {
"listingType": "Sale",
"locations": [
{
"state": "NSW",
"suburb": "Balgowlah",
"postcode": 2093,
"includeSurroundingSuburbs": True
}
]
}
url = "https://api.domain.com.au/v1/listings/residential/_search"
auth = {"Authorization":"Bearer "+access_token}
request = requests.post(url, data=search_parameters, headers=auth)
details=request.json()
我知道我的身份验证是正确的,因为我可以使用网站上的 Live API 来测试相同的请求(我必须选择客户端、秘密 ID 和项目以允许直接访问),并且我从上面的代码。
access_token:
{'access_token': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'expires_in': 43200,
'token_type': 'Bearer'}
request.json():
{'errors': {'parameters': ['Undefined error.']},
'message': 'The request is invalid.'}
我已经能够从这篇文章中实现笔记本。所以我可以确定我的客户和秘密 ID 已连接到域项目。
解决方案
@furas 有解决方案:
仔细看看这个例子:)
该示例使用"Content-Type":"text/json"
但您使用"application/json"
而不是"text/json"
推荐阅读
- javascript - 如果复选框为假,则从数组中删除项目
- c++ - 如何从头文件将运算符定义添加到现有结构?
- qt - 如何列出已安装 QtQuick 模块的版本
- asp.net-core - 占用空间最小的 ASP.NET Core 3.0 Web API
- angular - 找不到不同的支持对象'响应状态:200
- scala - akka-quartz-scheduler - “没有为调度找到匹配的石英配置” - QuartzSchedulerExtension 在两个参与者之间共享
- sql - 创建参考表
- flutter - 如何使用 textPainter 执行昂贵的计算
- java - 用java更改数据库日期
- android - MediaRecorder 冻结 UI 线程