문제

The following code in utils.py

manager = PoolManager()
data = json.dumps(dict) #takes in a python dictionary of json
manager.request("POST", "https://myurlthattakesjson", data)

Gives me ValueError: need more than 1 value to unpack when the server is run. Does this most likely mean that the JSON is incorrect or something else?

도움이 되었습니까?

해결책

Your Json data needs to be URLencoded for it to be POST (or GET) safe.

# 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)

I believe in python3 they made some changes that the data needs to be binary. See unable to Post data to a login form using urllib python v3.2.1

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top