在 Python 中,我如何发送 POST 请求,其中 URL 编码的参数有 5 个嵌套深度?

In Python, how can I send a POST request with URL-Encoded parameters that are 5 nests deep?

我想使用 Python 中的 requests 库发送一个 POST 请求 3. 我遇到的唯一困难是如何嵌入 urlencoded 表单部分。原始形式如下:

URLEncoded form:                                                                                                                         
data[type]: portion_send
data[attributes][style]: first_style
data[nodes][front][data][id]:1111
data[nodes][back][data][id]:1115

我能做的最好的事情是:

数据={"data":{"attributes":{"style":"first_style"},"nodes":{"front":{"data":{"id":"1111"}},"back":{"data":{"id":"1115"}}},"type" :"portion_send"}}

并将其嵌入 requests.post 函数中 params = dataparams = json.dumps(data)data = json.dumps(data),但都无济于事。

有人知道如何将其放入 post 请求吗?奇怪的是,嵌套跳得很深,让我失望了。谢谢!

Python 请求模块

我需要知道错误消息是什么,以帮助您使用 python requests 模块。

使用 Linux 或 MacOS Curl` 如果上述方法失败,你可以试试这个:

os.execv('curl -d data=value http://YourWebsite.com')

它在您的 PC 上执行一个单独的进程。如果你 运行 Windows,你可以从这里安装 curl:curl.haxx.se.