为了账号安全,请及时绑定邮箱和手机立即绑定

无法找出如何将以下 curl 请求转换为 Python 请求

无法找出如何将以下 curl 请求转换为 Python 请求

慕森王 2022-10-06 15:59:31
curl --location --request POST 'https://search-stagapi.example.com/search-new/search/v1/search/lambda' \--header 'Content-Type: application/json' \--header 'Content-Type: application/json' \--data-raw '{  "sort":null,  "per_page":12,  "scroll_id":null,  "session_id":null,  "q":"diapers",  "shingle_active":false,  "location":"110005",  "types":["allopathy","brand","sku","udp"],  "country":"",  "is_query_suggestion_applicable":false,  "debug":false,  "filters":null,  "facets":[{"field":"sku.brand.raw","name":"brand","type":"facet","range":null},{"field":"product_form","name":"product_form","type":"facet","range":null},{"field":"rx_required","name":"rx_required","type":"facet","range":null},{"field":"uses","name":"uses","type":"facet","range":null},{"field":"age","name":"age","type":"facet","range":null},{"field":"recommended","name":"recommended","type":"facet","range":null}],  "source_fields":["count"],  "query_filters":null,  "is_all":true}'我尝试使用 uncurl,但遇到了 data-raw 参数的问题,因为无法将整个请求转换为单个字符串。使用 uncurl 显示无效语法
查看完整描述

1 回答

?
慕妹3242003

TA贡献1824条经验 获得超6个赞

你可以这样做:


import requests

import json

headers = headers = {'content-type': 'application/json'}

payload = {json.dumps({

  "sort":null,

  "per_page":12,

  "scroll_id":null,

  "session_id":null,

  "q":"diapers",

  "shingle_active":false,

  "location":"110005",

  "types":["allopathy","brand","sku","udp"],

  "country":"",

  "is_query_suggestion_applicable":false,

  "debug":false,

  "filters":null,

  "facets":[{"field":"sku.brand.raw","name":"brand","type":"facet","range":null},{"field":"product_form","name":"product_form","type":"facet","range":null},{"field":"rx_required","name":"rx_required","type":"facet","range":null},{"field":"uses","name":"uses","type":"facet","range":null},{"field":"age","name":"age","type":"facet","range":null},{"field":"recommended","name":"recommended","type":"facet","range":null}],

  "source_fields":["count"],

  "query_filters":null,

  "is_all":true

})}


url = 'https://search-stagapi.example.com/search-new/search/v1/search/lambda' 


r = requests.post(url, params=payload, headers=headers)


查看完整回答
反对 回复 2022-10-06
  • 1 回答
  • 0 关注
  • 102 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信