您的邮递员请求是JSON正文。只需在Python中复制相同的主体即可。您的Python代码没有发送JSON,也没有发送与Postman示例相同的数据。
对于初学者,通过
data参数发送字典会将字典编码为
application/x-www-form-urlenpred表单,而不是JSON。其次,您似乎正在发送单个过滤器。
以下代码完全复制了您的Postman帖子:
import requestsfilters = {"filter": { "filters": [{ "field": "RCA_Assigned_Date", "operator": "gte", "value": "2017-05-31 00:00:00" }, { "field": "RCA_Assigned_Date", "operator": "lte", "value": "2017-06-04 00:00:00" }, { "field": "T_Subcategory", "operator": "neq", "value": "Temporary Degradation" }, { "field": "Issue_Status", "operator": "neq", "value": "Queued" }], "logic": "and"}}url = "http://10.61.202.98:8081/T/a/api/rows/cat/ect/tickets"response = requests.post(url, json=filters)
请注意,这里
filters是一个 Python 数据结构,并将其传递给
json关键字参数。使用后者有两件事:
- 将Python数据结构编码为JSON(产生与原始Postman正文值完全相同的JSON值)。
- 将
Content-Type
标头设置为application/json
(JSON
在选择raw
正文后,通过在下拉菜单中选择选项,就像在Postman配置中所做的那样)。
requests否则 只是一个HTTP API
,它不能使Cassandra做到比其他任何HTTP库更多的功能。该
urllib.request.urlopen代码发送
GET请求,并通过以下内容平凡地翻译为
requests:
def get_json(): url = "http://10.61.202.98:8081/T/a/api/rows/cat/ect/tickets" response = requests.get(url, params={'user_name': user}, timeout=15) return response.json()
我删除了
if分支,并使用
params参数将其替换,该参数将键-值对的字典转换为正确编码的URL查询(将用户名作为
user_name键传递)。
注意
json()响应中的呼叫;这负责解码从服务器返回的JSON数据。这仍然需要很长时间,您在这里没有过多地过滤Cassandra数据。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)