我想使用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数据。
您不需要
json
关键字参数;您正在将字典包装到另一个字典中。您还需要添加一个
Content-Type
头,将其设置为application/json
:相关问题 更多 >
编程相关推荐