Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法找到如何将下面的curl请求转换为Python请求_Python_Curl_Python Requests - Fatal编程技术网

无法找到如何将下面的curl请求转换为Python请求

无法找到如何将下面的curl请求转换为Python请求,python,curl,python-requests,Python,Curl,Python Requests,我尝试使用uncurl,但由于无法将整个请求转换为单个字符串,data raw参数面临一个问题。使用uncurl显示无效语法您可以执行以下操作: curl --location --request POST 'https://search-stagapi.example.com/search-new/search/v1/search/lambda' \ --header 'Content-Type: application/json' \ --header 'Content-Type: appl

我尝试使用uncurl,但由于无法将整个请求转换为单个字符串,data raw参数面临一个问题。使用uncurl显示无效语法

您可以执行以下操作:

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
}'

data=payload
更改为
params=payload
,然后重试。
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)