Drupal Authorization

Hello. I am trying to get services using authorization to work but I am running into an issue. I have services 6.x-1.x-dev installed, key authentication, json server and xmlrpc server. I have the node,search,system,user and views service turned on and I am running the latest stable drupal 6. I am trying to use the python script below to connect and return a node from services (I have also tried with a view and also using php but run into similar problems). If I go to site building -> services -> settings and remove the use keys and use sessid (and don't send the auth. parameters in my query) it works fine. However, I cannot get the node or view to work with the auth piece added. I am able to get a valid login returned - so that works. However, when I actually try to return the node or view I get the following error:

Traceback (most recent call last):
  File "test7.py", line 29, in <module>
    myobjects = drupal.node.get(hashMap.hexdigest(), domain, timestamp, nonce, session['sessid'], 3,[])
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/xmlrpclib.py", line 1147, in call
    return self.__send(self.__name, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/xmlrpclib.py", line 1437, in __request
    verbose=self.__verbose
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/xmlrpclib.py", line 1201, in request
    return self._parse_response(h.getfile(), sock)
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response
    return u.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/xmlrpclib.py", line 787, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: ''>

My code is:

#!/bin/python
import xmlrpclib, time, hmac, string, random, hashlib, pprint,sys
api = 'myapi'
url = 'myurl'
user = "myusername"
password = "mypass"
domain = "mydomain"
drupal = xmlrpclib.ServerProxy(url)
session = drupal.system.connect()
timestamp = str(int(time.mktime(time.localtime())))
nonce = "".join(random.sample(string.letters+string.digits, 10))
hashMap = hmac.new(api, "%s;%s;%s;%s" % (timestamp, domain, nonce, "user.login"), hashlib.sha256)
login = drupal.user.login(hashMap.hexdigest(), domain, timestamp, nonce, session['sessid'], user, password)
# works
pprint.pprint(login)
# I have tried various versions but cannot find one that works...Below are a few attempts
# myobjects = drupal.views.get(api,domain,timestamp,nonce,login['sessid'],'myobjects_by_name',[],[],0,0)
#myobjects = drupal.node.get(hashMap.hexdigest(),domain,timestamp,nonce,login['sessid'],1,[])
#myobjects = drupal.node.get(hashMap.hexdigest(), domain, timestamp, nonce, session['sessid'], 3,[])
myobjects = drupal.views.get(login['sessid'],'myobjects_by_Name',[],[],0,0)

I have tried a number of variations to get myobjects back - different arguments, etc. One confusing item is that when I ru n the following code:

print drupal.system.methodSignature('node.get')
['struct', 'string', 'string', 'string', 'string', 'string', 'int', 'array']
print drupal.system.methodSignature('views.get')
['array', 'string', 'string', 'string', 'string', 'string', 'string', 'array', 'array', 'int', 'int']
print drupal.system.methodSignature('user.login')
['struct', 'string', 'string', 'string', 'string', 'string', 'string', 'string']

The first argument reported back in all three is odd because when I look in Drupal at site building -> services ->browse for the node.get,views.get,and user.login the first argument says:

stringhash (required)
A valid API key.

for all three (node.get,views.get, user.login). However, as you can see the actual signature reported for node.get and user.login reports that it needs a struct while the views.get reports an array?? None of them are asking for a string as stated in the services browser...

Can anyone help with this? Thanks very much for your time.

Groups:
Login to post comments

methodSignature returns both

voidberg - Mon, 2009-08-10 11:42

methodSignature returns both the return type and the arguments, the first being the return type of the method.