2

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
1
  • postData in your code is a list - it should be a dict. Commented Jan 31, 2018 at 5:13

1 Answer 1

1
requests.post(data=json.dumps(postData))
Sign up to request clarification or add additional context in comments.

5 Comments

I tried that but it throws an error "message":"Invalid Json Array format passed in the request body. Please pass the valid json Array"
after change postData to a dict, you need to take the array out from request data first.
what does that mean?the API expects a request body with an array of Keyword types (string names or IDs)
postData = ['WIFI_CLONE', 'keyword#2'] requests.post(data=json.dumps(postData))
You should update your answer with your last comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.