Shinyshell Community Forums > Coding >
Problem with Python cookies in Chrome and Safari


[1]


May 29 02009, 12:58 GMT
Nick^
merciful justice

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
Now that I've started using the pre-alpha Chromium Mac as my usual browser, I've noticed something that really bugs me. Each time I quit the browser (this happens in Safari as well) my admin and chat cookies are both deleted; while Shinyshell's are not.

In Safari, when I looked at my cookie settings, Shinyshell's have an expiry date, while mine do not. In Firefox, however, both cookies work normally.

Here's my cookie setting code in the administration log in:

# Create a cookie expiration date 10 years from now 
timenow = electron.include.m.TIMENOW + 315360000
cookie_expiry = electron.misc.timeformat("%a, %d-%b-%Y %H:%M:%S GMT", timenow)

cookie_admin = "string"
cookie_string = "Set-Cookie: admin=%s; expires=%s" % (cookie_admin, cookie_expiry)
templating.header(cookie_string)
# Create a cookie expiration date 10 years from now
timenow = electron.include.m.TIMENOW + 315360000
cookie_expiry = electron.misc.timeformat("%a, %d-%b-%Y %H:%M:%S GMT", timenow)

cookie_admin = "string"
cookie_string = "Set-Cookie: admin=%s; expires=%s" % (cookie_admin, cookie_expiry)
templating.header(cookie_string)
]]>


What am I doing wrong?
______________________________
Lazurane

May 29 02009, 17:34 GMT
Kthar
Krme jedno bezglavo

Kthar's avatar
Location: kroatie
Post count: 106
hr
You're using Chromium Mac. Use Opera instead.

May 29 02009, 22:36 GMT
Nick^
merciful justice

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
No way. Opera's themes are horrible, and don't integrate with the Mac design at all. That is why I can't and don't use Opera. Plus, the widgets suck.
______________________________
Lazurane

May 31 02009, 00:08 GMT
Peter*
A Pythonic One

Peter's avatar
Location: US
Post count: 99

If I'm not mistaken, if you don't set an expiration date, they're deleted when you close the browser. I'm sure this isn't the answer. I just want to feel helpful. I also don't understand the code, sooo... I guess we can wait for Electron to show up.

May 31 02009, 01:58 GMT
Nick^
merciful justice

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
I am setting an expiry date, but Safari doesn't seem to recognise it.
______________________________
Lazurane

May 31 02009, 02:20 GMT
Peter*
A Pythonic One

Peter's avatar
Location: US
Post count: 99

That doesn't make sense; Python is interpreted server-side. O.o Sounds like a Safari problem...

May 31 02009, 17:03 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173

Sorry for the late post. It's not a Safari problem. I assume TIMENOW is declared in electron/include.py as

m.TIMENOW = time.time() 
m.TIMENOW = time.time()
]]>

In which case, the correct code is:

# Create a cookie expiration date 10 years from now  
timenow = TIMENOW + 315360000
cookie_expiry = electron.misc.timeformat("%a, %d-%b-%Y %H:%M:%S GMT", timenow)

cookie_admin = "string"
cookie_string = "Set-Cookie: admin=%s; expires=%s" % (cookie_admin, cookie_expiry)
templating.header(cookie_string)
# Create a cookie expiration date 10 years from now
timenow = TIMENOW + 315360000
cookie_expiry = electron.misc.timeformat("%a, %d-%b-%Y %H:%M:%S GMT", timenow)

cookie_admin = "string"
cookie_string = "Set-Cookie: admin=%s; expires=%s" % (cookie_admin, cookie_expiry)
templating.header(cookie_string)
]]>

Because "electron.include.m.TIMENOW" is a nonexistent object, and Python was probably just regarding it as 0. And that would effectively set the expiration date to December 29th 1979.

P.S. If you notice, the "m" object is actually __main__ (which is the namespace of the currently executing script). In effect, __main__.TIMESTAMP in the includes script (or m.TIMESTAMP in our case) just declares TIMESTAMP as a global value for easy use.

May 31 02009, 21:12 GMT
Kthar
Krme jedno bezglavo

Kthar's avatar
Location: kroatie
Post count: 106
hr
IS that Ribald the Barterman whose picture you've got in your avatar, Lec?

May 31 02009, 21:23 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173

Though do I not recall who that is, no. It is Eric Satie.

June 01 02009, 15:29 GMT
Kthar
Krme jedno bezglavo

Kthar's avatar
Location: kroatie
Post count: 106
hr
Ribald the Baterman is an NPC from Baldur's Gate II: Shadows of Amn. It was actually a trick question to lure you into posting a reply so that I can reply again and thus increase my, already amazing, post count.

June 01 02009, 19:33 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173

You really tricked me this time. Of course, merely by posting this I'm again being tricked into letting you accumulate yet another post.

June 01 02009, 20:49 GMT
Kthar
Krme jedno bezglavo

Kthar's avatar
Location: kroatie
Post count: 106
hr
Well, you knowest what they sayeth in Tennessee; actually, I don't know if it's in Tennessee, but I'm sure it's in Texas, so it's probably in Tennessee; fool me once, shame on you, fool me twice,.... youcan't get fooled again.

Are you ready?!?!?!?!?!

Go!

Out here in the fields I fight for my...rights to be fooled again. If anyone can guess the name of the band I'm aluding on here, IS! A! LAWNMOWER!!!!!!!

P.S. Note the A! which is 375F00.

June 02 02009, 20:16 GMT
Nick^
merciful justice

Nick's avatar
Location: Brisbane, Australia
Post count: 78
au
Sorry, Electron, but it doesn't work. Still.
______________________________
Lazurane

November 07 02009, 19:50 GMT
Peter*
A Pythonic One

Peter's avatar
Location: US
Post count: 99

import Cookie, datetime, os 

# Create a cookie expiration date 2 years from now
expire = datetime.datetime.now() + datetime.timedelta(730)
cookie_expiry = expire.strftime("%a, %d %b %Y %H:00:00 GMT")

cookie = Cookie.SimpleCookie(os.environ['HTTP_COOKIE'])

cookie_admin = "string"

cookie["admin"] = cookie_admin
cookie["betacookie"]["expires"] = cookie_expiry
print cookie
import Cookie, datetime, os

# Create a cookie expiration date 2 years from now
expire = datetime.datetime.now() + datetime.timedelta(730)
cookie_expiry = expire.strftime("%a, %d %b %Y %H:00:00 GMT")

cookie = Cookie.SimpleCookie(os.environ['HTTP_COOKIE'])

cookie_admin = "string"

cookie["admin"] = cookie_admin
cookie["betacookie"]["expires"] = cookie_expiry
print cookie
]]>

November 08 02009, 03:38 GMT
Faltzer
Member

Faltzer's avatar
Location: Glendale, New York
Post count: 38
us
I still don't get why everyone here always over-complicates what they want when there was obviously a good solution that actually works well is available.
______________________________
FHQ

November 09 02009, 20:47 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173

Cookie ships with Python and is also a respectable Python module. I conclude it's not over-complicating.


[1]



Forum Information
  Currently Active Members [detailed] (0 members and ? guests)
-
Forum Statistics
Topics: 0, Posts: 0, Members: 108.
Welcome to our newest member, adamthephantump
Most members online was 5, on August 28 2009, at 21:49:28.
Legend
    Forums with unread topics in them are indicated by a strong yellow colouring around the forum icon.
    Forums with no unread topics have the standard pale yellow colouring around the forum icon.
    Forums with a blue arrow icon will redirect you to a non-forum page.
    Locked forums have a little padlock by their icon. You won't be able to post in these forums.
Shinyshell Home | Contact | Staff List | Archive | Top 

Conventional Login

Don't have an account? You may want to create one.

OpenID Login
OpenID login and registration is usable, but not finished.
What is OpenID?
Search

(advanced search)
Site Stats
  Total members: 108
  Latest member: adamthephantump
  Members currently online: 0
  Most online: 5 - Aug 28, 2009 (21:49)
  Front page hits: 87998
Developer info
  Site version: 3.5 Alpha
  16 queries - 9 templates
Under the Spotlight
Collide Site
Collide make fabulously dreamy electronic-industrial music, they're one of my favourite bands! Give them a chance to take control of your life - myspace | youtube - "Euphoria".

Collide Site - Hits: 4597

5/5 (2) | Rate this site?