carte blanche
carte blanche

Reputation: 11476

how to send an array in python post data

I am trying to send an array as postData = {'WIFI_CLONE', 'keyword#2'} to python post request as follows and running into exception as too many values to unpack ?how to fix this?

def AddKeywordToProblem(self, problemID=None, keyword = ""):  
     if self._checklogin():
        problemID = '37040553'
        postData = ['WIFI_CLONE', 'keyword#2']
        logger.info(postData)
        r = requests.post(self._baseurl + 'problems/' + problemID + '/keywords',
                          headers=self._headers,data=postData,timeout=DEFAULT_REQUESTS_TIMEOUT)
        if r.status_code != 201:
            logger.warning('Error: Unable to get data. Server came back with:')
            logger.warning(r.text)
            return False
        return r.json()

Exception

too many values to unpack

Upvotes: 2

Views: 139

Answers (1)

guichao
guichao

Reputation: 198

requests.post(data=json.dumps(postData))

Upvotes: 1

Related Questions