You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求对应Python Requests代码的等效curl命令(附代码示例)

如何将Python Requests POST请求转为等效curl命令?

Hey there! Let's work out the correct curl command that matches your Python Requests code.

First, let's recap your original Python code:

import requests 
response = requests.request("POST" , url = "https://services27.ieee.org/fellowsdirectory/getpageresultsdesk.html" , data = { 'pageNum': 3 } ) 
print(response.text)

The key thing here is that when you use data with a dictionary in Requests, it sends the payload as form-encoded data (Content-Type: application/x-www-form-urlencoded), not JSON. Your initial curl attempt was sending JSON, which is why it wasn't matching the Python request's behavior.

Correct Equivalent curl Command

curl -X POST -d 'pageNum=3' https://services27.ieee.org/fellowsdirectory/getpageresultsdesk.html

Alternatively, if you want explicit URL encoding (useful if your values have special characters), you can use:

curl -X POST --data-urlencode 'pageNum=3' https://services27.ieee.org/fellowsdirectory/getpageresultsdesk.html

Quick Explanation

  • Your Python code uses data={'pageNum': 3}: This tells Requests to encode the key-value pair like an HTML form would, setting the appropriate Content-Type header automatically.
  • The curl -d flag does exactly this—it sends form-encoded data, matching what your Python code is doing. Your original attempt used JSON syntax ({"pageNum": "3"}), which would set the Content-Type to application/json, which isn't what the Python request is sending.

If you want to double-check that the requests match, add the -v flag to the curl command to view the full request headers and payload, which should align with what Requests generates.

内容的提问来源于stack exchange,提问作者user1424739

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:22:10