python_webservices_library icon indicating copy to clipboard operation
python_webservices_library copied to clipboard

"NoneType" object is not subscriptable

Open jogjayr opened this issue 13 years ago • 8 comments

I have problems logging in with the default script:

url = 'http://<REDACTED>/service/v2/rest.php' user = '<REDACTED>' passwd = '<REDACTED>' import sugarcrm session = sugarcrm.Sugarcrm(url, user, passwd) Connecting to: http://<REDACTED>/service/v2/rest.php Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/sugarcrm/sugarcrm.py", line 58, in init self.login(username, password) File "/usr/local/lib/python2.7/dist-packages/sugarcrm/sugarcrm.py", line 112, in login self.id = x["id"] TypeError: 'NoneType' object is not subscriptable

Also posted on StackOverflow in case I'm doing something wrong: http://stackoverflow.com/questions/7751416/sugarcrm-python-api-wrapper-nonetype-object-is-not-subscriptable

Appreciate your attention and time. Thanks.

jogjayr avatar Oct 13 '11 17:10 jogjayr

Hi, jogjayr. You're doing it right, there's something wrong somewhere else.

Is it LDAP authentication enabled in the SugarCRM installation you're trying to log into?

Thanks

luisbarrueco avatar Oct 13 '11 20:10 luisbarrueco

LDAP authentication is not enabled. Is it a requirement for API access?

jogjayr avatar Oct 13 '11 21:10 jogjayr

No, I meant that I get the same error in a SugarCRM instance that has LDAP auth enabled. I thought that might have been the issue.

I'll keep watching, thanks.

luisbarrueco avatar Oct 13 '11 21:10 luisbarrueco

Excuse me, jogjayr.

Could you please elaborate on how your environment is set up? What version of SugarCRM are you running?

Could you please try to run this snippet (replacing your url, user and password back)?


import sugarcrm import json import urllib url = 'http://localhost/sugarcrm/service/v2/rest.php' user = 'admin' passwd = 'password'

session = sugarcrm.Sugarcrm(url) auth = {'user_auth' : {'user_name' : user, 'password' : sugarcrm.passencode(passwd)}} auth = json.dumps(auth) args = {'method': 'login', 'input_type': 'json', 'response_type' : 'json', 'rest_data' : auth} params = urllib.urlencode(args) print params response = urllib.urlopen(url, params) print response response = response.read() print response result = json.loads(response) print result


Thanks a lot

luisbarrueco avatar Oct 20 '11 15:10 luisbarrueco

I have version 6.0.1 running on a hosted Linux (Bluehost, probably Redhat) with Apache server.

I tried out your code (i changed json.loads to json.load because response is an fp style object). I get the result is:

None

Thanks for keeping up with this issue. I really appreciate it. I've gotten no joy on StackOverflow.

jogjayr avatar Oct 20 '11 22:10 jogjayr

Got it! Apparently I introduced a regression merging the last pull request. Funny thing, it breaks (not so much) older versions of SugarCRM such as yours.

I'm guessing you got the code by pulling on the repo, could you please go back one commit (issuing "git checkout afa81ae7e60425e9104abe7045ede4698ef5cda1")? (remember reinstall by running "python2.7 setup.py install" if that was your case).

I'm sorry for the trouble, the API shouldn't behave differently on different SugarCRM versions, that's why there is API versioning (v2, v3, v4...).

Thanks for reporting the bug

luisbarrueco avatar Oct 21 '11 23:10 luisbarrueco

I had the same problem here (ldap authent enabled). I've solved the problem changing line 68 in sugarcrm.py from : args = {'method': method, 'input_type': 'json', 'response_type' : 'json', 'rest_data' : data} to args = {'method': method, 'input_type': 'JSON', 'response_type' : 'JSON', 'rest_data' : data}

(capitalize JSON) with small JSON, my sugar instance was always returning 'null' for response

ThomasChiroux avatar Nov 23 '11 15:11 ThomasChiroux

Had same issue. Doing both of these fixed this issue for me. Thanks

SinOB avatar Nov 29 '11 10:11 SinOB