Strange String comparison problem (python script)
Hi folks, this is my python script: request=context.REQUEST user=request['AUTHENTICATED_USER'] print "user: ", user, "<br>" print "container", container.getId(), "<br>" print "context: ", context.getId(), "<br>" if user == context.getId(): print "names match, upload ok" else: print "username does not match context id" the if conditional *always* fails, even when username and context id are the same (here's the return printed output): user: udo container gallery context: udo username does not match context id ??? Can someone please shed some light what I am doing wrong? Version is Zope 2.5.1/Python 2.1.3 on Linux Mandrake 8.2 Cheers & thanks much in advance, Uwe -- Uwe Schuerkamp http://www.schuerkamp.de/ GnuPG Fingerprint: 2093 20B8 B861 9358 A356 B01A E145 9249 5D27 33EA PGP Fingerprint: 2E 13 20 22 9A 3F 63 7F 67 6F E9 B1 A8 36 A4 61
On Thu, Aug 29, 2002 at 12:53:50PM -0500, Mark McEahern wrote:
if user == context.getId():
Have you tried:
if str(user) == str(context.getId()):
I'm just guessing.
... but I think you guess right, because user is actually a user object, not a string. When printed, it is implicitly converted to a string. But comparisons won't do implicit conversions. So you need to do it explicitly, using str(). -- Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
Hi all I used a script got from this list for adding a large number of users to my CMF site. It works very well with the users appearing in the acl list. However, the users cannot login. The password does not seem to be set properly. What am I missing ? TIA Chetan PS: The script is ----------------------------------------------------- import string def addAuthUsers(self, REQUEST, infile='/home1/sepg/auth.txt'): """ import users from infile, a space delimited file... """ #output - just used to let me know who got imported. output=open('/home1/sepg/userout.txt','w') infile=open( infile ,'r') output.write('opened %s\n'%infile) for line in infile.readlines(): line=string.strip(line) (name,password)=string.split(line,' ') try: self.acl_users.manage_users(submit='Add',REQUEST={'name':name,'password ':password,'confirm':password,'roles':['member',]}) output.write("added user name=%s, password=%s\n"%(name,password)) except: output.write("couldn't add user name=%s, password=%s\n"%(name,password) )
There are a number of things to try: 1) Check your output file, do the passwords match what you expect them to be? 2) Where's the acl_user folder, and where are your using trying to log in? If the acl_users folder isn't at the root level, and users are trying to log in at the root level, it's not going to work. 3) Reset a users password through the ZMI, and then try and log in. If this works, it implies that the password is being set with special characters, or a leading or trailing space chearcter. Mark Chetan Kumar wrote:
Hi all I used a script got from this list for adding a large number of users to my CMF site. It works very well with the users appearing in the acl list. However, the users cannot login. The password does not seem to be set properly. What am I missing ? TIA Chetan
PS: The script is ----------------------------------------------------- import string def addAuthUsers(self, REQUEST, infile='/home1/sepg/auth.txt'): """ import users from infile, a space delimited file... """ #output - just used to let me know who got imported. output=open('/home1/sepg/userout.txt','w') infile=open( infile ,'r') output.write('opened %s\n'%infile) for line in infile.readlines(): line=string.strip(line) (name,password)=string.split(line,' ') try:
self.acl_users.manage_users(submit='Add',REQUEST={'name':name,'password ':password,'confirm':password,'roles':['member',]}) output.write("added user name=%s, password=%s\n"%(name,password)) except: output.write("couldn't add user name=%s, password=%s\n"%(name,password) )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
user=request['AUTHENTICATED_USER']
This is a user object, not the users id. user = request['AUTHENTICATED_USER'].getUserName() Is the actual users name. -- Andy McKay Agmweb Consulting http://www.agmweb.ca
participants (6)
-
Andy McKay -
Chetan Kumar -
Mark Gibson -
Mark McEahern -
Paul Winkler -
Uwe Schuerkamp