亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法找出如何將以下 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 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號