Lispython / human_curl

Simple Human wrapper for cURL library
http://h.wrttn.me/human_curl
Other
205 stars 43 forks source link

Error when using human_curl to POST json data to a REST API #26

Closed bmacauley closed 11 years ago

bmacauley commented 11 years ago

I get the following error when trying to POST JSON data to a REST API...

Error: 'dict' object is not callable

2013-04-11 15:25:21,836 - core - 417 - DEBUG - Setup custom headers Content-Type: application/json 2013-04-11 15:25:21,836 - core - 430 - DEBUG - Set timeout: 15 2013-04-11 15:25:21,836 - core - 479 - DEBUG - Setup user agent Mozilla/5.0 (compatible; human_curl; 0.1.1; +http://h.wrttn.me/human_curl) 2013-04-11 15:25:21,836 - core - 537 - DEBUG - Use method POST for request 2013-04-11 15:25:21,836 - core - 558 - DEBUG - self._data is string 2013-04-11 15:25:21,836 - core - 559 - DEBUG - ('self._data', '{"username": "j", "password": "k"}') 2013-04-11 15:25:23,945 - rest - 89 - ERROR - Error: 'dict' object is not callable

A snippet of the code...it works when using the normal requests lib

import json import human_curl as requests

import requests

payload = {}
headers = {}
payload['username'] = self.user
payload['password'] = self.pwd
headers['Content-Type'] = 'application/json'

try:
r = requests.post(login_url,
data=json.dumps(payload),
headers=headers)
if r.json()['success'] is False:
log.error(' login error: {0}'.format(r.json()['error']))
log.error(' login...FAILED!')
else:
self.cookies = r.cookies

     log.info(' login...SUCCESS')                              

except Exception, err:
log.error('Error: {0}'.format(err))
log.error(' login...FAILED!')

Lispython commented 11 years ago

I think, because r.json is propety, not method.

bmacauley commented 11 years ago

yep...it works...slight variation from requests