【发布时间】:2015-11-24 14:28:28
【问题描述】:
我想使用 urllib3 库通过 requests 库发出 POST 请求,因为它具有连接池和重试等功能。但我不能
找到以下POST 请求的替代品。
import requests
result = requests.post("http://myhost:8000/api/v1/edges", json={'node_id1':"VLTTKeV-ixhcGgq53", 'node_id2':"VLTTKeV-ixhcGgq51", 'type': 1 })
这适用于 requests 库,但我无法将其转换为 urllib3 请求。
我试过了
import json
import urllib3
urllib3.PoolManager().request("POST","http://myhost:8000/api/v1/edges", body=json.dumps(dict(json={'node_id1':"VLTTKeV-ixhcGgq53", 'node_id2':"VLTTKeV-ixhcGgq51", 'type': 1 })))
问题是在POST 请求中以json 作为键传递原始json 数据。
【问题讨论】:
标签: python python-2.7 python-requests urllib3