Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'initialize': 0.07; 'string': 0.09; 'cookie': 0.09; 'exist,': 0.09; 'inserted': 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; 'number?': 0.16; 'query,': 0.16; 'respond.': 0.16; 'subject:fails': 0.16; 'subject:when': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'value.': 0.19; 'select': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header :User-Agent:1': 0.23; "aren't": 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'gets': 0.27; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'correct': 0.29; 'am,': 0.29; "doesn't": 0.30; 'asked': 0.31; 'code': 0.31; 'expire': 0.31; 'filed': 0.31; 'object.': 0.31; 'piece': 0.31; 'probably': 0.32; 'problem': 0.35; 'display': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'impression': 0.36; 'skip:o 20': 0.38; 'little': 0.38; 'does': 0.39; 'how': 0.40; 'even': 0.60; 'browser': 0.61; 'back': 0.62; 'times': 0.62; "you'll": 0.62; "you've": 0.63; 'more': 0.64; 'chance': 0.65; 'to:addr:gmail.com': 0.65; '8bit%:92': 0.71; '8bit%:100': 0.72; 'emails.': 0.78; 'subject:get': 0.81; 'batchelder': 0.84; 'feedback,': 0.84 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=CBPqFmIVV00f8Q5z85FOqsTZeXbwWdn+WUDYdQUlMAE=; b=mRRi/1e/ItueQ9RITqKypWolh6U+dFXMGh1vH/QgQjYlm5BIBd8J7AdOG1AW4mILU6 /aiuElCBSpjThhgg9tvHTeBIweDPS/Kw6HtSuQ3sdo+t0CRvcZhHfWf4PrL8jSFhGB0q YwP3yNr/YmIoGU60ZEWBheywHSybW99d/4tsH2HLi+zzV+by7fSPQxdKeeqBAKscvQ6b T0ayb5MWKsCaEe9KHcosqqbhkvfOZBwLgQp8s2z0jeuv08haT1/8By6YzOll6pUZ3FuO H+okf14PHPxkyASCQOzw3cFPQUuFwT7sYxUmoX0EHahgzPcHcpmBh4oFSRDBv5dnep6o q6YA== X-Received: by 10.224.40.195 with SMTP id l3mr12418385qae.44.1380984867128; Sat, 05 Oct 2013 07:54:27 -0700 (PDT) Sender: Ned Batchelder Date: Sat, 05 Oct 2013 10:54:25 -0400 From: Ned Batchelder 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: =?UTF-8?B?zp3Or866zr/PgiDOkc67zrXOvs+Mz4DOv8+FzrvOv8+C?= Subject: Re: Select fails when cookie tried to get a numeric value References: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380984876 news.xs4all.nl 15971 [2001:888:2000:d::a6]:42449 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56193 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? > > Nikos: stop sending so many emails. You've asked this question 3 times now in this thread. You aren't even giving people a chance to respond. If you want immediate feedback, use IRC. Email takes a little longer. --Ned.