Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top