I'm new with Python and I need to build a Python library that connect to our API service sending some json data, everything works fine but one thing, I need to send some dict of dicts doing a POST request:
def create_project(self, project):
print project
params = simplejson.dumps(project)
print params
req = requests.post(self.url+'/projects/addSpeedy.json',
data=params,
auth=HTTPBasicAuth(self.api_id, self.api_key),verify=False)
data = simplejson.loads(req.text)
return data
the project param I'm passing to that function contains the following structure:
script = {
'part001': 'HI',
'part002': 'WORLD'
}
project = {
'title': 'Project posted from Python Carrot',
'script': script,
'remarks': "I want the voice be similar to Bugs Bunny.",
'test': '1'
}
However when doing the request the API tells me the 'title' field which is required is missing, however when printing the data in the function everything seems fine, the dict json encode was something I saw in the requests site for this cases: http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests
I've tried other ways with mixed results it doesnt work the way it should, also the problem its not the API since we have libraries in other languages and it works fine.