Select fails when cookie tried to get a numeric value

Νίκος Αλεξόπουλος nikos.gr33k at gmail.com
Sat Oct 5 12:53:05 EDT 2013


Στις 5/10/2013 7:42 μμ, ο/η Ned Batchelder έγραψε:
>
> A better solution is to check to see if you got None:
>
>      if cookie.get('ID') is None:
>          # make a new cookie....

I have tried everythign even wgat you suggested right now:
here is is:

# initialize cookie and retrieve cookie from clients broswer
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )

if cookie.get('ID') is not None:
	cookieID = cookie['ID'].value
else:
	x = random.randrange(0, 10000)
	cookie['ID'] = x
	cookie['ID']['path'] = '/'
	print( cookie )
	cookieID = x

print( '''Content-type: text/html; charset=utf-8\n''' )
print( cookieID )

For some reason althogh the cookie does exist in my browser the returnd 
value of cookieI D = cookie['ID'].value is always: Set-Cookie: ID=7482

instead of just the number.
But why?  isnt value to return just the number?

You can see the result of the above code yourself at the top left when 
you visit: http://superhost.gr

it always retursn the whole string instead of just the number...

why can we isolate th damn number only?
in the else i manages to isolate it but not when i try to retrive it.



More information about the Python-list mailing list