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


Groups > comp.lang.python > #56207

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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <nedbat@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'initialize': 0.07; 'none:': 0.07; 'string': 0.09; 'answering': 0.09; 'cookie': 0.09; 'except:': 0.09; 'exist,': 0.09; 'inserted': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'random': 0.14; '#this': 0.16; "'/'": 0.16; 'bottom-most': 0.16; 'fails.': 0.16; 'frame,': 0.16; 'irc,': 0.16; 'number?': 0.16; 'query,': 0.16; 'subject:fails': 0.16; 'subject:when': 0.16; 'sys.exit(0)': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'pace': 0.19; 'value.': 0.19; '>>>': 0.22; 'select': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; 'skip:" 40': 0.26; 'this:': 0.26; 'second': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'correct': 0.29; 'on,': 0.29; 'am,': 0.29; "doesn't": 0.30; 'returned': 0.30; 'code': 0.31; 'serve': 0.31; "skip:' 10": 0.31; '>>>>': 0.31; 'expire': 0.31; 'fast.': 0.31; 'filed': 0.31; 'object.': 0.31; 'piece': 0.31; 'yourself.': 0.31; 'file': 0.32; 'probably': 0.32; 'another': 0.32; 'problem': 0.35; 'display': 0.35; 'problem.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'impression': 0.36; 'returning': 0.36; 'thanks': 0.36; "i'll": 0.36; 'too': 0.37; 'list': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'pm,': 0.38; 'does': 0.39; 'enough': 0.39; 'how': 0.40; 'new': 0.61; 'browser': 0.61; 'you.': 0.62; 'back': 0.62; "you'll": 0.62; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'bottom': 0.67; 'of:': 0.68; '8bit%:92': 0.71; '8bit%:100': 0.72; 'emails.': 0.78; 'subject:get': 0.81; 'batchelder': 0.84; 'seriously,': 0.84; 'text/html;': 0.84; 'problems?': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=wJKJIJQz/TfMkv5c5OC+u029kBWXUgpiTZcjh0ecc3k=; b=WgQyzF77pHA168wM1NDL9KKGAf9lTSx41Ha6IkYkN0okiYE5m2je5xSRj5Pqp5g0W2 HzQa2E8NX9CnmY7/REBinONJTEkKVLnaR9htBvkRxnM/9BH56ezN0DERSAWf/AaDdZyE gkOW8R9r3SCFjW4Pb2ZMil5Via8TybzpePVo8dh27QH9Xs0jORSvF2th0XTgcmaErvOF 5KpO4jXYzxow+krLxLB+2eLfRkuNcIkS4KX3Fe/m3ZnrR0faHCij7g/uCWJMYqDcYC0P 5qwb9DXNgPEPRlACoJEdLBl4it/BT8TEcGoj0wrWqMUqj7TfhyawQwkilRL2Pv/iW8ZM pDpw==
X-Received by 10.224.103.194 with SMTP id l2mr1920961qao.118.1380991342318; Sat, 05 Oct 2013 09:42:22 -0700 (PDT)
Sender Ned Batchelder <nedbat@gmail.com>
Date Sat, 05 Oct 2013 12:42:21 -0400
From Ned Batchelder <ned@nedbatchelder.com>
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8
MIME-Version 1.0
To Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com>
Subject Re: Select fails when cookie tried to get a numeric value
References <l2p4o4$4ht$1@dont-email.me> <mailman.743.1380981201.18130.python-list@python.org> <l2p8cl$j06$4@dont-email.me> <mailman.748.1380985965.18130.python-list@python.org> <l2pckd$f30$2@dont-email.me> <mailman.751.1380989312.18130.python-list@python.org> <l2pds7$ol2$1@dont-email.me> <l2pe26$ol2$2@dont-email.me>
In-Reply-To <l2pe26$ol2$2@dont-email.me>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.754.1380991748.18130.python-list@python.org> (permalink)
Lines 146
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1380991748 news.xs4all.nl 15880 [2001:888:2000:d::a6]:59293
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:56207

Show key headers only | View raw


On 10/5/13 12:17 PM, Νίκος Αλεξόπουλος wrote:
> Στις 5/10/2013 7:14 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:
>> Στις 5/10/2013 7:08 μμ, ο/η Ned Batchelder έγραψε:
>>>
>>> On 10/5/13 11:52 AM, Νίκος Αλεξόπουλος wrote:
>>>> Στις 5/10/2013 6:12 μμ, ο/η Ned Batchelder έγραψε:
>>>>> On 10/5/13 10:40 AM, Νίκος Αλεξόπουλος wrote:
>>>>>> Στις 5/10/2013 4:53 μμ, ο/η Ned Batchelder έγραψε:
>>>>>>
>>>>>>>  From reading the bottom-most frame, you can see that the 
>>>>>>> problem is
>>>>>>> that "val" is an http.cookies.Morsel object.  This means you 
>>>>>>> probably
>>>>>>> tried to use a cookie object as data in your SQL query, and MySQL
>>>>>>> doesn't know what to do with that object.  You'll have to use a 
>>>>>>> more
>>>>>>> primitive piece of data in your query.
>>>>>>
>>>>>> # initialize cookie
>>>>>> cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
>>>>>> cookie.load( cookie )
>>>>>> cookieID = cookie.get('ID')
>>>>>>
>>>>>> # 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
>>>>>>     cookieID = cookie.get('ID')
>>>>>>     print( cookie )
>>>>>>
>>>>>>
>>>>>> In the above code i try to retrive the cookie form the visitor's
>>>>>> browser and if it does nto exist i create one.
>>>>>>
>>>>>>
>>>>>>
>>>>>> For some reason i think CookieID nevers gets inserted itnot the
>>>>>> database that's why mysql's select statemnt fails.
>>>>>>
>>>>>> 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"
>>>>>>
>>>>>> The mysql filed CookieID is of datatype's int(5) so it cannto store
>>>>>> this value.
>>>>>>
>>>>>> If iam correct and thi is trully the problem then how can i just get
>>>>>> the random number part out the whole string?
>>>>>>
>>>>>> Do you see something wrong?
>>>>>> Why cookie['ID'] retuned this string back and not just the number?
>>>>>>
>>>>>>
>>>>>
>>>>> Thanks for being patient.  Where you have this:
>>>>>
>>>>>      cookieID = cookie.get('ID')
>>>>>
>>>>> you actually want this:
>>>>>
>>>>>      cookieID = cookie.get('ID').value
>>>>>
>>>>> --Ned.
>>>>
>>>>
>>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114]   File
>>>> "/home/nikos/public_html/cgi-bin/metrites.py", line 84, in <module>
>>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114] cookieID =
>>>> cookie.get('ID').value
>>>> [Sat Oct 05 15:51:02 2013] [error] [client 108.162.229.114]
>>>> AttributeError: 'NoneType' object has no attribute 'value'
>>>>
>>>
>>> Nikos: you know enough to understand what is going on here.
>>>
>>> This list will not serve you well if you take every error message and
>>> paste it into an email without trying to get to the bottom of it
>>> yourself.  At the very least, a Google search on, "AttributeError:
>>> 'NoneType' object has no attribute 'value'" will find you some answers.
>>>
>>> I've said it before, I'll say it again:  slow down.
>>>
>>> --Ned.
>>
>>
>> cookieID = cookie.get('ID').value
>>
>> is not returning what you said it will return
>>
>> and if cookie.get('ID') doenst exist it returns the error
>> AttributeError: 'NoneType' object has no attribute 'value'
>>
>> These are 2 problem.
>>
>> value aint being returned thw ehole Set-Cookie: ID=some_number is being
>> returned instead as tou cna see at http://superhost.gr/
>>
>> and the second problem is
>>
>> that if the cookie dosnt exist i get the error of: AttributeError:
>> 'NoneType' object has no attribute 'value'
>>
>> whne this line is tryign to be executed:
>> cookieID = cookie.get('ID').value
>>
>> How can i deal with thse 2 problems?
>>
> The best solution i cna think of is put the whole thing into a try: block
>
> try:
>     cookieID = cookie.get('ID').value
> except:
>     cookie['ID'] = random.randrange(0, 10000)
>     cookie['ID']['path'] = '/'
>     print( cookie )
>     cookieID = cookie['ID'].value
>
> print( '''Content-type: text/html; charset=utf-8\n''' )
>
> print( cookieID )
> sys.exit(0)
>
> That will avoid the NoneType errot but:
>
> that still print out:
> Set-Cookie: ID=7413
>
> instead of just the number
>

Nikos, you are now answering your own emails.  You are going too fast.  
Slow down, think through a solution before writing another email.  And 
seriously, consider IRC, you will be able to have a conversation with 
someone.  The email pace doesn't suit you.

A better solution is to check to see if you got None:

     if cookie.get('ID') is None:
         # make a new cookie....

--Ned.

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