utils.py
manager = PoolManager()
data = json.dumps(dict) #takes in a python dictionary of json
manager.request("POST", "https://myurlthattakesjson", data)
运行服务器时给我ValueError: need more than 1 value to unpack
。这很可能意味着JSON不正确还是其他什么?
答案 0 :(得分:0)
您的Json数据需要进行URL编码,以使其成为POST(或GET)安全。
# import parser
import urllib.parse
manager = PoolManager()
# stringify your data
data = json.dumps(dict) #takes in a python dictionary of json
# base64 encode your data string
encdata = urllib.parse.urlencode(data)
manager.request("POST", "https://myurlthattakesjson", encdata)
我相信python3他们做了一些改变,数据需要是二进制的。见unable to Post data to a login form using urllib python v3.2.1