Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56199

Re: Select fails when cookie tried to get a numeric value

From Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com>
Newsgroups comp.lang.python
Subject Re: Select fails when cookie tried to get a numeric value
Date 2013-10-05 18:50 +0300
Organization A noiseless patient Spider
Message-ID <l2pcf6$f30$1@dont-email.me> (permalink)
References <l2p4o4$4ht$1@dont-email.me> <mailman.743.1380981201.18130.python-list@python.org> <l2p8cl$j06$4@dont-email.me> <mailman.749.1380987077.18130.python-list@python.org>

Show all headers | View raw


Στις 5/10/2013 6:06 μμ, ο/η Zero Piraeus έγραψε:
> :
>
> On Sat, Oct 05, 2013 at 05:40:23PM +0300, Νίκος Αλεξόπουλος wrote:
>> When i print CookieID i was under the impression i would see a
>> random number like '5369' but instead it display the follwong.
>>
>> Set-Cookie: ID="Set-Cookie: ID=5369"
>
> On Sat, Oct 05, 2013 at 05:47:54PM +0300, Νίκος Αλεξόπουλος wrote:
>> When i print CookieID i was under the impression i would see a
>> random number like '5369' but instead it display the follwong.
>>
>> Set-Cookie: ID="Set-Cookie: ID=5369"
>
> Please don't give identical or near-identical replies to multiple
> messages in the thread; other members of the list are either reading all
> of your posts or none of them, so repeating yourself like this is only
> going to irritate whoever is reading.
>
> Since printing cookieID doesn't produce the output you expect, the
> obvious next step is to look up the documentation for whatever kind of
> object it is. You can find out its type with
>
>      type(cookieID)
>
> ... and then once you know that type (let's say for the sake of argument
> it's a Biscuit object), find out about that type of object's attributes
> either by googling for the docs or at the interpreter with
>
>      help(Biscuit)
>
> As previously mentioned, there's likely to be some kind of 'value'
> attribute that will return just the number you want.
nikos@superhost.gr [~/www/cgi-bin]# python
Python 3.3.2 (default, Aug 26 2013, 06:41:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, random
>>> from http import cookies
>>> cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
>>> cookieID = cookie.get('ID').value
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'value'


And if you go to my webpage http://superhost.gr at the top corner you 
see that allthough i use this code to get the value of the retrieved 
cookie or set the value if ti do

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

# if browser cookie does not exist, set it
if not cookieID:
	cookie['ID'] = random.randrange(0, 10000)
	cookie['ID']['path'] = '/'
	cookie['ID']['expires'] = 60*60*24*365		#this cookie will expire in a month
	print( cookie )
	cookieID = cookie['ID'].value

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

print( cookieID )
sys.exit(0)

The output is: Set-Cookie: ID=1376

But how is this possible since we applied the .value attribute in the 
cookie?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 16:38 +0300
  Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 09:53 -0400
    Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:40 +0300
      Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 10:54 -0400
      Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 11:12 -0400
        Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 18:31 +0300
          Re: Select fails when cookie tried to get a numeric value Andreas Perstinger <andipersti@gmail.com> - 2013-10-05 17:47 +0200
          Re: Select fails when cookie tried to get a numeric value Chris Angelico <rosuav@gmail.com> - 2013-10-06 09:36 +1100
        Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 18:52 +0300
          Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 12:08 -0400
            Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 19:14 +0300
              Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 19:17 +0300
                Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 12:42 -0400
                Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 19:53 +0300
      Re: Select fails when cookie tried to get a numeric value Zero Piraeus <z@etiol.net> - 2013-10-05 12:06 -0300
        Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 18:50 +0300
  Re: Select fails when cookie tried to get a numeric value Chris Angelico <rosuav@gmail.com> - 2013-10-05 23:59 +1000
    Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:24 +0300
      Re: Select fails when cookie tried to get a numeric value Chris Angelico <rosuav@gmail.com> - 2013-10-06 00:28 +1000
        Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:30 +0300
          Re: Select fails when cookie tried to get a numeric value Ned Batchelder <ned@nedbatchelder.com> - 2013-10-05 10:43 -0400
            Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:47 +0300
          Re: Select fails when cookie tried to get a numeric value Zero Piraeus <z@etiol.net> - 2013-10-05 11:44 -0300
          Re: Select fails when cookie tried to get a numeric value MRAB <python@mrabarnett.plus.com> - 2013-10-05 17:51 +0100
      Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 17:28 +0300
      Re: Select fails when cookie tried to get a numeric value Andreas Perstinger <andipersti@gmail.com> - 2013-10-05 18:56 +0200
        Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-05 20:38 +0300
  Re: Select fails when cookie tried to get a numeric value Benjamin Rovny <rdr.vladimir@gmail.com> - 2013-10-05 09:35 -0500
  Re: Select fails when cookie tried to get a numeric value Terry Reedy <tjreedy@udel.edu> - 2013-10-05 18:06 -0400
  Re: Select fails when cookie tried to get a numeric value Denis McMahon <denismfmcmahon@gmail.com> - 2013-10-05 23:36 +0000
    Re: Select fails when cookie tried to get a numeric value Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-10-06 08:20 +0300
      Re: Select fails when cookie tried to get a numeric value Denis McMahon <denismfmcmahon@gmail.com> - 2013-10-06 14:57 +0000
      Re: Select fails when cookie tried to get a numeric value Piet van Oostrum <piet@vanoostrum.org> - 2013-10-06 22:16 -0400

csiph-web