salesforce-python-sdk icon indicating copy to clipboard operation
salesforce-python-sdk copied to clipboard

update method causes JSONDecoderERROR:

Open EnGassa opened this issue 9 years ago • 12 comments

>>> sf._connection.Contact.update(['0031a000002KTbYAAW', {'lastname': 'beep'}])
PATCH: Sending request to https://na24.salesforce.com/services/data/v33.0/sobjects/Contact/0031a000002KTbYAAW

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/python_env/local/lib/python2.7/site-packages/salesforce/api.py", line 163, in update
    return self.__get_api(soap).__getattr__(self.name).update(data)
  File "/usr/local/python_env/local/lib/python2.7/site-packages/salesforce/utils.py", line 184, in authenticate_and_call
    return func(self, *args, **kwargs)
  File "/usr/local/python_env/local/lib/python2.7/site-packages/salesforce/salesforceRestApi.py", line 171, in update
    data=json.dumps(records))
  File "/usr/local/python_env/local/lib/python2.7/site-packages/salesforce/salesforceRestApi.py", line 222, in __send_request
    **kwargs)
  File "/usr/local/python_env/local/lib/python2.7/site-packages/salesforce/utils.py", line 157, in send_request
    return response.json()
  File "/usr/local/python_env/local/lib/python2.7/site-packages/requests/models.py", line 799, in json
    return json.loads(self.text, **kwargs)
  File "/usr/local/python_env/local/lib/python2.7/site-packages/simplejson/__init__.py", line 505, in loads
    return _default_decoder.decode(s)
  File "/usr/local/python_env/local/lib/python2.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/python_env/local/lib/python2.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 1 column 1 (char 0)

EnGassa avatar Apr 22 '15 04:04 EnGassa

This is parsing problem. Can you verify the response and see if it is a valid json. I would be appreciated if I can see the response. Thanks

htarevern avatar Apr 22 '15 17:04 htarevern

The response here is a requests.models.Response object since httplib returns it. In case of non SOAP requests, in your code in utils.py on line 157 you call the response.json() to convert it to JSON. Since this code is used for all other calls too and seems to be working for those. I am guessing it is a problem isolated to the Salesforce update operation response.

In order to prove this hypothesis, I recently dived deep into the requests module and more specifically the json() method in it. It seems that the update response doesnt have encoding set unlike the others.

In [5]: sf.query('select firstname, id from contact limit 1')
GET: Sending request to https://na24.salesforce.com/services/data/v33.0/query/

<class 'requests.models.Response'>

JSON Content(encoding: UTF-8)
{
  "totalSize" : 1,
  "done" : true,
  "records" : [ {
    "attributes" : {
      "type" : "Contact",
      "url" : "/services/data/v33.0/sobjects/Contact/0031a000002KTbzAAG"
    },
    "FirstName" : "MUHAHA",
    "Id" : "0031a000002KTbzAAG"
  } ]
}

In [6]: sf.Contact.update(['0031a000002KTbzAAG', {'firstname': 'SomethingNew'}])
PATCH: Sending request to https://na24.salesforce.com/services/data/v33.0/sobjects/Contact/0031a000002KTbzAAG

<class 'requests.models.Response'>

JSON Content(encoding: None)
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
.
.
.
.

EnGassa avatar Apr 22 '15 19:04 EnGassa

Can you look at the network package and let me know the response. Or you can add a print in my sdk before line 157

htarevern avatar Apr 22 '15 19:04 htarevern

The response is a 200: <Response [200]>

I am printing response.text too. This prints out the content of the response, and works for all the queries I make, except for Update.

EnGassa avatar Apr 22 '15 19:04 EnGassa

What is the content of the response.text in the case of update?

htarevern avatar Apr 22 '15 19:04 htarevern

The type of response.text is unicode and the value is blank.

type: <type 'unicode'>, content:

EnGassa avatar Apr 22 '15 20:04 EnGassa

okay. I will have a fix maybe by end of the day. Thanks. I should check for empty response

htarevern avatar Apr 22 '15 20:04 htarevern

Thanks Hormoz. Appreciate the quick turnaround. Let me know if I can help with anything.

EnGassa avatar Apr 23 '15 00:04 EnGassa

Hormoz, Whether the issue has been resolved ? I am still getting this error.

aliasneo1 avatar May 18 '15 13:05 aliasneo1

any update?

pitbulk avatar Jul 13 '15 16:07 pitbulk

i will fix this issue as soon as possible. I am really sorry for inconvenience

htarevern avatar Jul 30 '15 23:07 htarevern

Is there any progress in this issue? Bcoz i am trying to use it and gives same error for update. Please let me know.

KunalRamteke avatar May 17 '17 04:05 KunalRamteke