Python Forum
Cookies - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cookies (/thread-15606.html)



Cookies - Donald - Jan-24-2019

Hallo,

this code to read Cookies from FireFox runs without error, but without result. In the console it shows cookies.

import sqlite3
import os

cookies =  'c:\\users\\xxx\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xxx.default\\cookies.sqlite'

try:
    conn = sqlite3.connect(cookies)
    c = conn.cursor()
    c.execute("select host, name, value from moz_cookies")
          
    for row in c:
        host = str(row[0])
        name = str(row[1])
        value = str(row[2])
        print (host + ': ' + name + ': ' + value)
except Exception as e:
    if 'encrypted' in str(e):
        print ('encrypted')
Thank you

regards


RE: Cookies - buran - Jan-24-2019

Don't use catch all except (i.e. using general Exception).
at the moment add else part to the if in the except
except Exception as e:
    if 'encrypted' in str(e):
        print ('encrypted')
    else:
        print(e)
I guess there is some exception that you shadow and don't see it.
EDIT: yes, I get "unable to open database file"


RE: Cookies - Donald - Jan-24-2019

@buran,

thank you, but there was no hidden exception.

I used Python 3 for Windows, of course with the correct UserName and Profile. For "places" I get access to the database.

regards


RE: Cookies - DPaul - Apr-15-2020

Hi,

Done the same thing : with result!
Try these field names in the table : moz_cookies
'select host, expiry, creationTime, lastAccessed from moz_cookies'
The date format is epoch-time, and make sure you truncate to 10 positions to get a sensible date.
(At least that is what i found)
Paul