Re: [Tutor] mod_python authentication
Alan, I am very impressed! This one goes to my knowledge base. Thanks a lot. 2009/12/7 Alan Plum : > On Mo, 2009-12-07 at 09:35 -0400, Rayon wrote: >> How do I Check for an active login session on every page that requires >> authentication >> >> Been at this for days and it’s holding me back can someone plz help >> me with some code examples. > > To understand sessions you first need to understand that HTTP is a > stateless protocol: you connect, send your request, receive a response > and the connection is closed. > > Sessions add a layer of abstraction to create functionality the protocol > doesn't provide: multiple requests are grouped and treated as belonging > together. > > There are several ways to accomplish this. The most straightforward way > would be remembering the client's IP and persisting variables as > relative to that IP -- problem is, IPs are unreliable, can be faked, and > do not provide a strong indicator of identity (while an IP only resolves > to one machine at a time, that machine may be acting as a gateway or > proxy for multiple users connected from other machines -- also, many IPs > are dynamically allocated thanks to ISPs). > > Another method is putting the session's ID in the URLs you display to > your users. This creates a lot of problems, though: the session is only > maintained as long as the user uses exactly the URLs you provide (they > won't stay logged in, for example, if they bookmark a plain URL without > the session ID) and it may accidentally be shared between different > users by passing the URL verbatim (most users don't know enough about > URLs to clean session IDs out of them before sending them to other > people -- or don't care!). > > The fix for this is usually to restrict the session to an IP (which is > why you often see the checkbox "Restrict my session to this IP" in > log-in forms), but that screws you over if your IP may randomly change > between consecutive requests and thus may break the illusion. > > The most common and reliable choice is the good old session cookie: a > cookie (a small data string) is sent to the browser, containing just the > session ID (and, sometimes, non-critical data such as accessibility > settings if the website provides them). Because the browser is normally > restricted to a single user, the session ID is stored in a safe place -- > except it isn't really because some people use e.g. internet cafés and > such which may not dispose of session data regularly. Also, a user may > access the same site from different devices or places, therefore > hoarding cookies for different sessions creating consistency problems. > > Still, cookies are the easiest and most reliable way to store a session > ID and non-critical data. If you couple them with IP restrictions and a > conservative expiry time (i.e. duration of inactivity until the session > becomes invalid or "expired" and all associated variables are wiped) and > provide a fallback mechanism for users who disabled (or can't accept) > cookies, you should have most scenarios covered (although some sites > actually just stick to cookies and provide no fallbacks). > > So once you've decided on a mechanism to persist the session ID, let's > see what a session actually is. In most cases you want to use them for a > log-in mechanism: the user enters their username and password, > successfully, and is welcomed by a personal greeting and a new > navigation subtree that was previously unavailable. > > In this case it may be tempting to simply store the user's ID and log-in > state in a cookie, but that'd be incredibly silly because the user can > easily edit them if he knows about cookies (even worse things can happen > if you provide useful variables like "is_admin: False"). Instead you > should store those variables in a safe place ("persist" them) like a > database or special session files. > > The session ID acts as a key to the session file or database entry, so > you need to make sure it's not easily guessable: many websites use very > long seemingly-randomly generated strings (a hash of the user's IP and > the millisecond time of the session's creation may yield good results). > > Also, if you want to persist something, make sure it's easily > persistable. A string variable is child's play, an open file on the > other hand may cause locking problems and if you deal with large volumes > of data (e.g. binary file uploads kept in memory) you may quickly run > out of space. > > If you don't want to have to deal with all of these considerations and > instead prefer something shrinkwrapped and ready for use, Google is your > friend. Depending on what you use there are plenty of CGI-compatible > packages and WSGI frameworks to choose from. > > > Cheers, > > Alan Plum > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___
Re: [Tutor] Tutor Digest, Vol 70, Issue 5
from InformIT's website. Here's the direct link: >>> >>> http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/python/python2python3.pdf >> >> >> It didn't work for me I always got forwarded to the Book "home page" on >> InformIT > > Strange. Worked for me yesterday and again just now. > > Kent > > > -- > > Message: 5 > Date: Wed, 2 Dec 2009 15:13:20 +0100 > From: Joerg Woelke > To: tutor@python.org > Subject: Re: [Tutor] Moving from Python 2 to Python 3: A 4 page > "cheatsheet" > Message-ID: <20091202141320.gc9...@localhost> > Content-Type: text/plain; charset=us-ascii > > * Alan Gauld [091202 15:07]: >> >http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/python/python2python3.pdf >> >> >> It didn't work for me I always got forwarded to the Book "home page" >> on InformIT > Worked for me with wget(1). > > -- > You are capable of planning your future. > > > -- > > Message: 6 > Date: Wed, 2 Dec 2009 09:26:08 -0600 > From: Wayne Werner > To: Joerg Woelke > Cc: tutor@python.org > Subject: Re: [Tutor] Moving from Python 2 to Python 3: A 4 page > "cheatsheet" > Message-ID: > <333efb450912020726x22cffc60q6b911387dc13a...@mail.gmail.com> > Content-Type: text/plain; charset="windows-1252" > > On Wed, Dec 2, 2009 at 8:13 AM, Joerg Woelke wrote: > >> Alan Gauld [091202 15:07]: >> > > >> http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/python/python2python3.pdf >> > >> > >> > It didn't work for me I always got forwarded to the Book "home page" >> > on InformIT >> Worked for me with wget(1). >> > > > And for me with Google Chrome on Ubuntu... > -Wayne > -- > To be considered stupid and to be told so is more painful than being called > gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, > every vice, has found its defenders, its rhetoric, its ennoblement and > exaltation, but stupidity hasn?t. - Primo Levi > -- next part -- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20091202/f33c0b0b/attachment.htm> > > -- > > ___ > Tutor maillist - tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 70, Issue 5 > > -- Regards, Aivars Enkuzens ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqlite3 Python25 parameter binding problem withUPDATEplease help
Thanks, Alan, for your advice. I fully agree with you - I still need to understand basic Python (I actually warned that I am a complete noob) and how it works. And probably I need a couple of goof books. I once told you that I consider your website an excellent one and I am going there from time to time and will do it again. Maybe I am trying to do the things which are too advanced for my level of python knowledge - databases, web development, which I understand are considered as advanced topics but the reason is that for me I need a real project to work with to learn a programming language. That was the case also with VBA (visual basic for applications) - learning for the sake of learning almost never worked with me. It does not mean I am an expert in VBA - far from it! But I had this project working with MS Excel VBA+ MS SQL Server Express 2005 T-SQL - an automated financial accounting consolidated reporting application. I am pumping data from two remote Interbase/Firebird databases, putting it in a local MS SQL Server DB, processing with T-SQL and doing the reporting with Excel. Now I am working to do the same with Python and SQLite at the same time learning on my way them both. And if you work on a real thing there are many bits and pieces which are coming up - and its not like this 'spam' and 'egg' thing all the time. Also I am completely self-taught in programming. I see what was my problem in particular in this case and I understand it now. And I will try not to bother people on this list too often. Or If I do please feel free tell me to [EMAIL PROTECTED] off and do some more reading! Again, thank you Alan for the help! Aivars 2008/12/3 Alan Gauld <[EMAIL PROTECTED]>: > "aivars" <[EMAIL PROTECTED]> wrote > >> Finally I managed to get it working! >> >> I had to remove [year] braces from the second argument - year. > > You really need to do some reading on basicv Python before > you go any further, otherwise you will never understand what > you are doing. > > That is what I told you was wrong in the first place - you can't > pass a list of values (even of one value) into a database field. > But you obviously didn't realize that putting square brackets > (not braces which are {} and signify a dictionary) indicates > a list. > >> reason I used [] was the posts we exchanged recently (7th of November) >> about CGI script where it was recommended by Kent that I put [] around >> string argument: > > But that was an entirely different scenario, again you need to do some > basic level reading so that you understand what we are telling you. > Blindly using "poke and hope" techniques leads to an excercise > in frustration for you and us both. > >> The second argument to execute() is a *sequence* of parameter values. >> A string is a sequence of characters, so by passing a plain string you >> are saying that each character of the string is a parameter to the >> SQL. >> >> Try adding braces around the parameter to make list: >> cur.execute("insert into test (name) values (?)", [sPath]) > > Notice, Kent told you to "make a list" by putting[] around > your string. But in that case the arument was looking for a sequence > (eg list) of values. In your case you were trying to insert a list of values > into a single field which you can't do in normal SQL > >> Now the year argument is string so I thought I should do the same >> again but it is not working. > > Yes but it is a single string so you need to pass a single string. > In the previous case the SQL was looking for a list of arguments > but you passed a single string so the execute interpreted that > as a list of letters. > > You must ensure that the arguments in the execute match > what the SQL is expecting. And that usually means both matching > what you defined the database to be and the nature of the operation. > >> The reason is of course is that I am new to python and there are so >> many things to learn so the question really is why in this case there >> were no [] or () necessary? > > See above, but you really need to take the time out to understand > the basics of Python. > > Try reading my tutorial, in particular the "raw materials" topic > which covers the different Python data types. Then try my database > topic near the end. But ideally just take a few hours - literally an > afternoon will do - to go through any beginners tutorial. They will > all cover these elementary issues. > > >>>>> Perhaps but I think it is the list parameter that it doesn't like. >>>>> Unless I misunderstand the syntax. >>>>> >>>>> -- >>>>> Alan Gauld >>>>> Author of the Learn to Program web site >>>>> http://www.freenetpages.co.uk/hp/alan.gauld > > > Alan G. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqlite3 Python25 parameter binding problem with UPDATEplease help
Hello again, Finally I managed to get it working! I had to remove [year] braces from the second argument - year. The reason I used [] was the posts we exchanged recently (7th of November) about CGI script where it was recommended by Kent that I put [] around string argument: Quote The second argument to execute() is a *sequence* of parameter values. A string is a sequence of characters, so by passing a plain string you are saying that each character of the string is a parameter to the SQL. Try adding braces around the parameter to make list: cur.execute("insert into test (name) values (?)", [sPath]) Kent Unquote Now the year argument is string so I thought I should do the same again but it is not working. The reason is of course is that I am new to python and there are so many things to learn so the question really is why in this case there were no [] or () necessary? Thanks in advance Aivars 2008/12/2 aivars <[EMAIL PROTECTED]>: > Interestingly, when simply testing like this: > > import sqlite3, sys > sPATH=r'e:\pythonexamples\aivars2.db' > oCon=sqlite3.connect(sPATH) > > cur=oCon.cursor() > > oCon.execute("""UPDATE rezerve SET latusaldo = ? WHERE gads = ? > """,(6000.0,'2006')) > > oCon.commit() > > > it works. Therefore I am stuck since it looks like there is something > wrong in below function. > > Thanks, > > Aivars > > > 2008/12/2 aivars <[EMAIL PROTECTED]>: >> Alan, >> Thanks. >> >> Ok I should have been more precise and give more code >> There is what I do: >> >> def starpiba(year, month, day): >>datumsno=str(year+'-01-01') #beginning of year date >>datumsuz=str(year+'-'+month+'-'+day) #period end date >> >>result = (atlikumiBeiguKurss(year, month, day)- >> atlikumiDienasKurss(year, month, day)) >>##print result >>oCon=sqlite3.connect(sPATH) >>if result<=0: >>print abs(result) >>oCon.execute("UPDATE rezerve SET latusaldo =? where gads >> =?;",(result, [year])) >>oCon.commit() >>else: >>##print 'aivars' >>oCon.execute("UPDATE rezerve SET latusaldo =? where gads >> =?;",(result, [year])) >> >> Please bear in mind I am a noob in Python and I write spaggeti code. >> >> There is a table in my sqlite database called rezerve which shows the >> breakdown of a consolidated reserves item in a consolidated balance >> sheet report (if that says anything to you) by years. For the previous >> years the numbers does not change since they are already reported but >> for the current year it may change month by month until reported. >> Therefore, I wanted to update the numbers for the current year. >> >> The above python function works OK. >> >> Thanks >> >> Aivars >> >> >> 2008/12/2 Alan Gauld <[EMAIL PROTECTED]>: >>> >>> "aivars" <[EMAIL PROTECTED]> wrote >>> >>>> oCon.execute("UPDATE rezerve SET latusaldo =? where gads =?;",(result, >>>> [year])) >>>> oCon.commit() >>>> >>>> it throws me the error: >>>> sqlite3.InterfaceError: error binding parameter 1 probably unsupported >>>> type >>> >>> I assume its the [year] value it objects to. >>> I'm not sure what you expect SQLite to do with a list as a value, it does >>> not support a list type field. >>> >>>> All works OK when using INSERT with the same parameters. >>> >>> Are you sure? You can insert a list into a field? >>> >>>> Maybe I should as this question on sqlite list? >>> >>> Perhaps but I think it is the list parameter that it doesn't like. >>> Unless I misunderstand the syntax. >>> >>> -- >>> Alan Gauld >>> Author of the Learn to Program web site >>> http://www.freenetpages.co.uk/hp/alan.gauld >>> >>> ___ >>> Tutor maillist - Tutor@python.org >>> http://mail.python.org/mailman/listinfo/tutor >>> >> > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sqlite3 Python25 parameter binding problem with UPDATEplease help
Interestingly, when simply testing like this: import sqlite3, sys sPATH=r'e:\pythonexamples\aivars2.db' oCon=sqlite3.connect(sPATH) cur=oCon.cursor() oCon.execute("""UPDATE rezerve SET latusaldo = ? WHERE gads = ? """,(6000.0,'2006')) oCon.commit() it works. Therefore I am stuck since it looks like there is something wrong in below function. Thanks, Aivars 2008/12/2 aivars <[EMAIL PROTECTED]>: > Alan, > Thanks. > > Ok I should have been more precise and give more code > There is what I do: > > def starpiba(year, month, day): >datumsno=str(year+'-01-01') #beginning of year date >datumsuz=str(year+'-'+month+'-'+day) #period end date > >result = (atlikumiBeiguKurss(year, month, day)- > atlikumiDienasKurss(year, month, day)) >##print result >oCon=sqlite3.connect(sPATH) >if result<=0: >print abs(result) > oCon.execute("UPDATE rezerve SET latusaldo =? where gads > =?;",(result, [year])) >oCon.commit() >else: >##print 'aivars' >oCon.execute("UPDATE rezerve SET latusaldo =? where gads > =?;",(result, [year])) > > Please bear in mind I am a noob in Python and I write spaggeti code. > > There is a table in my sqlite database called rezerve which shows the > breakdown of a consolidated reserves item in a consolidated balance > sheet report (if that says anything to you) by years. For the previous > years the numbers does not change since they are already reported but > for the current year it may change month by month until reported. > Therefore, I wanted to update the numbers for the current year. > > The above python function works OK. > > Thanks > > Aivars > > > 2008/12/2 Alan Gauld <[EMAIL PROTECTED]>: >> >> "aivars" <[EMAIL PROTECTED]> wrote >> >>> oCon.execute("UPDATE rezerve SET latusaldo =? where gads =?;",(result, >>> [year])) >>> oCon.commit() >>> >>> it throws me the error: >>> sqlite3.InterfaceError: error binding parameter 1 probably unsupported >>> type >> >> I assume its the [year] value it objects to. >> I'm not sure what you expect SQLite to do with a list as a value, it does >> not support a list type field. >> >>> All works OK when using INSERT with the same parameters. >> >> Are you sure? You can insert a list into a field? >> >>> Maybe I should as this question on sqlite list? >> >> Perhaps but I think it is the list parameter that it doesn't like. >> Unless I misunderstand the syntax. >> >> -- >> Alan Gauld >> Author of the Learn to Program web site >> http://www.freenetpages.co.uk/hp/alan.gauld >> >> ___ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor >> > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] sqlite3 Python25 parameter binding problem with UPDATE please help
Hello, Does sqlite3 in python 2.5 supports parameter bindings in UPDATE statement? When I do like the following: oCon.execute("UPDATE rezerve SET latusaldo =? where gads =?;",(result, [year])) oCon.commit() it throws me the error: sqlite3.InterfaceError: error binding parameter 1 probably unsupported type All works OK when using INSERT with the same parameters. On Google I found that python with MySQL supports this syntax (sorry I am not able to find the link now) but I am not able to get it working with sqlite3 Thanks in advance Maybe I should as this question on sqlite list? Aivars ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with sqlite replace function
Hello, Denis, Please try what sqlite3.version shows on your machine? Thanks aivars 2008/11/7 spir <[EMAIL PROTECTED]>: > aivars a écrit : >> >> Thanks, John, >> Yes it seems you are right. The ActiveState python version I have >> installed have sqlite 2.3.2 only. I find it strange. > > I also have ActiveState's python (mainly for its very good doc) and I get: >>>> >>> import sqlite3 >>>> sqlite3.sqlite_version > '3.3.4' > > Denis > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] problem with simple sqlite script
Kent, Yesss!! That did the trick! It's worth to remeber. Thank you very much! Aivars 2008/11/7 Kent Johnson <[EMAIL PROTECTED]>: > On Fri, Nov 7, 2008 at 3:49 AM, aivars <[EMAIL PROTECTED]> wrote: > >> import sqlite3 >> >> sPath=r'e:\pythonexamples\aivars2.db' >> >> con=sqlite3.connect(sPath) >> cur=con.cursor() >> cur.execute("insert into test (name) values (?)",sPath) > > The second argument to execute() is a *sequence* of parameter values. > A string is a sequence of characters, so by passing a plain string you > are saying that each character of the string is a parameter to the > SQL. > > Try adding braces around the parameter to make list: > cur.execute("insert into test (name) values (?)", [sPath]) > > Kent > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] problem with simple sqlite script
Thanks, Alan, here is a create statement: CREATE TABLE "test" ("name" TEXT) And also I would like to thank you for you web page. Classes and OOP seems to start to make sense to me now slowly after I am reading your material. Aivars 2008/11/7 Alan Gauld <[EMAIL PROTECTED]>: > > "aivars" <[EMAIL PROTECTED]> wrote > >> sPath=r'e:\pythonexamples\aivars2.db' >> >> con=sqlite3.connect(sPath) >> cur=con.cursor() >> cur.execute("insert into test (name) values (?)",sPath) >> con.commit() > >> File "E:\PythonExamples\test.py", line 7, in >> cur.execute("insert into test (name) values (?)",sPath) >> ProgrammingError: Incorrect number of bindings supplied. The current >> statement uses 1, and there are 28 supplied. > > It looks like name expects a char and you are giving it a string. > How did you define the name field of test? > Can you send us the create statement? > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] problem with simple sqlite script
Hello, I am getting frustrated. I have been successfully inserting, deleting, etc records with python and sqlite no problem. Suddenly the following very simple scrip does not work: import sqlite3 sPath=r'e:\pythonexamples\aivars2.db' con=sqlite3.connect(sPath) cur=con.cursor() cur.execute("insert into test (name) values (?)",sPath) con.commit() here is an error message Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 307, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=0) File "C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 631, in run exec cmd in globals, locals File "E:\PythonExamples\test.py", line 7, in cur.execute("insert into test (name) values (?)",sPath) ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 28 supplied. What the hell is going on? I have used the syntax with (?) successfully before! I tested and found out that above script allows me to insert only single character into database. Then it works. Using ActiveState python 2.5, WinXP Thanks for any hint. Aivars ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with sqlite replace function
John, just to add to my previous post. after copying sqlite3.dll (3.6.2) version into Python25\DLLs directory and running import sqlite3 dir(sqlite3) >>> sqlite3.version '2.3.2' >>> sqlite3.version_info (2, 3, 2) >>> sqlite3.sqlite_version_info (3, 6, 2) >>> sqlite3.sqlite_version '3.6.2' and now my scrip happily runs with sqlite replace function. I am just curious why there are so many different version properties and why now they differ from sqlite3.version? Of course it seems Python now is running sqlite version 3.6.2 since my script accepts replace function Thanks, Aivars 2008/11/7 aivars <[EMAIL PROTECTED]>: > Thanks, John, > Yes it seems you are right. The ActiveState python version I have > installed have sqlite 2.3.2 only. I find it strange. > I see that on a python website there is is a new version Python26 > relesed. Should i go on and install Python26? I understand that I can > install pure Python from python website and after that I can install > Mark Hammonds PythonWin to get other things for windows? Or maybe I > will reinstall ActiveState Python25 and install Python25 from the > official website > > Copying dll to c:\python25\DLLs directory did not help - it still > shows version sqlite version 2.3.2. which I also do not understand why > > Re user defined function - it is one of the ways to go probably > quickest but I would like to have newer version of sqlite being > already with python > > I am noob in Python still > > Thanks for your input > > Aivars > > > > 2008/11/6 John Fouhy <[EMAIL PROTECTED]>: >> 2008/11/7 aivars <[EMAIL PROTECTED]>: >>> I use python 2.5.2.2 (activestate), WinXP, sqlite version 3.6.2 >> >> Hi Aivars, >> >> I believe python has its own built-in sqlite, rather than using the >> version you installed independently. So it is possible that the >> python version of sqlite is older than 3.6.2 and does not yet have the >> replace() function. >> >> (run 'import sqlite3' and then examine 'sqlite3.sqlite_version' to see >> what version you are using) >> >> You could try replacing sqlite3.dll in your python25\dlls directory >> with the DLL from your sqlite installation (make a backup first :-) ). >> Alternatively, you could define the replace() function in python and >> then add it to your database: see >> http://www.initd.org/pub/software/pysqlite/doc/usage-guide.html#creating-user-defined-functions >> . >> >> HTH. >> >> -- >> John. >> > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with sqlite replace function
Thanks, John, Yes it seems you are right. The ActiveState python version I have installed have sqlite 2.3.2 only. I find it strange. I see that on a python website there is is a new version Python26 relesed. Should i go on and install Python26? I understand that I can install pure Python from python website and after that I can install Mark Hammonds PythonWin to get other things for windows? Or maybe I will reinstall ActiveState Python25 and install Python25 from the official website Copying dll to c:\python25\DLLs directory did not help - it still shows version sqlite version 2.3.2. which I also do not understand why Re user defined function - it is one of the ways to go probably quickest but I would like to have newer version of sqlite being already with python I am noob in Python still Thanks for your input Aivars 2008/11/6 John Fouhy <[EMAIL PROTECTED]>: > 2008/11/7 aivars <[EMAIL PROTECTED]>: >> I use python 2.5.2.2 (activestate), WinXP, sqlite version 3.6.2 > > Hi Aivars, > > I believe python has its own built-in sqlite, rather than using the > version you installed independently. So it is possible that the > python version of sqlite is older than 3.6.2 and does not yet have the > replace() function. > > (run 'import sqlite3' and then examine 'sqlite3.sqlite_version' to see > what version you are using) > > You could try replacing sqlite3.dll in your python25\dlls directory > with the DLL from your sqlite installation (make a backup first :-) ). > Alternatively, you could define the replace() function in python and > then add it to your database: see > http://www.initd.org/pub/software/pysqlite/doc/usage-guide.html#creating-user-defined-functions > . > > HTH. > > -- > John. > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] please help with sqlite replace function
Hello, I am stuck now. I have a sqlite database with a table calendar (which is an auxilary calendar table containing dates, years, months, days) >From sqlite prompt I can run the following query without any problem: SELECT replace( datums,'-','' ) FROM calendar where Y='2008' and M='5' It gives me back date strings in the format MMDD. But when I run it from the python script it gives me the following error: sqlite3.OperationalError: no such function: replace. Script is simple as follows: import sqlite3 spath=r'e:\pythonexamples\aivars2.db' sql="SELECT replace(datums,'-','') FROM Calendar where Y='2008' and M='5'" cn=sqlite3.connect(spath) for row in cn.execute(sql): print row[0] When I run the script without the replace function in select statement it runs OK. I use python 2.5.2.2 (activestate), WinXP, sqlite version 3.6.2 Thanks for any tip. maybe I should ask this to sqlite mailing list? Aivars ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with simple python CGI script
Hello, Lie, I renamed the directory back to Cgi-bin and the scripts are NOT working. Going back to cgi-bin it works. I also do not understand why. Aivars 2008/10/26 Lie Ryan <[EMAIL PROTECTED]>: > On Sun, 26 Oct 2008 08:32:52 +, Alan Gauld wrote: > >> "aivars" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >>>I finally get the script working! >>> >>> I renamed the script directory from Cgi-bin to cgi-bin just as Alan >>> told. >> >> I'm glad it worked but I confess I'm not sure why it worked. The >> interpreter was apparently finding your script OK but it was the >> environment that was messed up. I don't fully understand the interaction >> going on there. But in things web related I've learned that consistency >> throughout is usually helpul! >> >> Alan G. >> > > I wouldn't have thought it could work, since Windows is case insensitive > and web server is required understand URL as case insensitive. Why that > Cgi-bin and cgi-bin differs on a windows-based server is beyond me. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with simple python CGI script
I finally get the script working! I renamed the script directory from Cgi-bin to cgi-bin just as Alan told. Many thanks to all you who responded Aivars 2008/10/26 aivars <[EMAIL PROTECTED]>: > Thanks John and Alan > > I get the following error when I run the script from IDLE: > > Traceback (most recent call last): > File "C:\Cgi-bin\friends1.py", line 15, in >who = form['person'].value > File "C:\Python25\lib\cgi.py", line 567, in __getitem__ >raise KeyError, key > KeyError: 'person' > > > Aivars > Windows XP, python 2.5 > > 2008/10/26 John Pomni <[EMAIL PROTECTED]>: >> what error do you get? It works without any changes on my Linux machine >> with python 2.5 >> >> John >> >> On Sat, 2008-10-25 at 21:33 +0300, aivars wrote: >>> It does not work neither as script or from command line. I will try to >>> find the guy Wesley Chun and ask him >>> >>> 2008/10/25 John Pomni <[EMAIL PROTECTED]>: >>> > Hi, >>> > >>> > The script does not work from command line but I guess you do not have >>> > any problems running it as CGI? >>> > >>> > I like cgitb modules for debugging purposes very much. >>> > >>> > http://www.python.org/doc/2.5.2/lib/node566.html >>> > >>> > Jan >>> > >>> > On Fri, 2008-10-24 at 18:55 +0300, aivars wrote: >>> >> Thanks very much, Kent, >>> >> >>> >> So it seems that directory /cgi-bin should be a subdirectory to that >>> >> directory from which the web server was started/is running. That >>> >> worked and Deitel's script - getting time displayed finally worked. >>> >> >>> >> still banging mu head with Wesley Chun's simple example - >>> >> >>> >> #!C:\python25\python.exe >>> >> >>> >> import cgi >>> >> >>> >> reshtml = '''Content-Type: text/html\n >>> >> >>> >> Friends CGI Demo (dynamic screen) >>> >> >>> >> Friends list for: %s >>> >> Your name is: %s >>> >> You have %s friends. >>> >> ''' >>> >> >>> >> form = cgi.FieldStorage() >>> >> who = form['person'].value >>> >> howmany = form['howmany'].value >>> >> print reshtml % (who, who, howmany) >>> >> >>> >> It gives me the following error: >>> >> Traceback (most recent call last): >>> >> File "C:\Cgi-bin\friends1.py", line 15, in >>> >> who = form['person'].value >>> >> File "C:\Python25\lib\cgi.py", line 567, in __getitem__ >>> >> raise KeyError, key >>> >> KeyError: 'person' >>> >> >>> >> I understand python is saying that there is no such a key in a directory. >>> >> >>> >> The HTML form looks like this. it is displayed correctly both in FF and >>> >> IE >>> >> >>> >> >>> >> >>> >> Friends CGI Demo (static screen) >>> >> >>> >> Friends list for: NEW USER >>> >> >>> >> Enter your Name: >>> >> >>> >>How many friends do you have? >>> >> 0 >>> >>10 >>> >>25 >>> >>50 >>> >>100 >>> >> >>> >> >>> >> Thanks again, >>> >> >>> >> Aivars >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> 2008/10/24 Kent Johnson <[EMAIL PROTECTED]>: >>> >> > On Fri, Oct 24, 2008 at 10:25 AM, aivars <[EMAIL PROTECTED]> wrote: >>> >> >> Hello, >>> >> >> >>> >> >> I am learning python. >>> >> >> >>> >> >> I start the python CGI server like this: >>> >> >> >>> >> >> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core >>> >> >> Python Programming chapter 20.5) >>> >> >> >>> >> >> The server starts in command prompt on windows XP by answering: >>> >> >> Serving HTTP on 0.0.0.0 port 8000... >>> >> >> >>> >> >> Next I want to run this simple CGI script (from Deitel Python How to >>> >> >> Program chapter 6). it is supposed to print out current date and time >>> >> >> in a browser >>> >> > >>> >> > The CGI script should me in a /cgi-bin subdirectory of the dir where >>> >> > you run the script. The URL to run the CGI will then be something like >>> >> > http:://localhost:8000/cgi-bin/myscript.py >>> >> > >>> >> > Kent >>> >> > >>> >> ___ >>> >> Tutor maillist - Tutor@python.org >>> >> http://mail.python.org/mailman/listinfo/tutor >>> > >>> > >> >> > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with simple python CGI script
Thanks John and Alan I get the following error when I run the script from IDLE: Traceback (most recent call last): File "C:\Cgi-bin\friends1.py", line 15, in who = form['person'].value File "C:\Python25\lib\cgi.py", line 567, in __getitem__ raise KeyError, key KeyError: 'person' Aivars Windows XP, python 2.5 2008/10/26 John Pomni <[EMAIL PROTECTED]>: > what error do you get? It works without any changes on my Linux machine > with python 2.5 > > John > > On Sat, 2008-10-25 at 21:33 +0300, aivars wrote: >> It does not work neither as script or from command line. I will try to >> find the guy Wesley Chun and ask him >> >> 2008/10/25 John Pomni <[EMAIL PROTECTED]>: >> > Hi, >> > >> > The script does not work from command line but I guess you do not have >> > any problems running it as CGI? >> > >> > I like cgitb modules for debugging purposes very much. >> > >> > http://www.python.org/doc/2.5.2/lib/node566.html >> > >> > Jan >> > >> > On Fri, 2008-10-24 at 18:55 +0300, aivars wrote: >> >> Thanks very much, Kent, >> >> >> >> So it seems that directory /cgi-bin should be a subdirectory to that >> >> directory from which the web server was started/is running. That >> >> worked and Deitel's script - getting time displayed finally worked. >> >> >> >> still banging mu head with Wesley Chun's simple example - >> >> >> >> #!C:\python25\python.exe >> >> >> >> import cgi >> >> >> >> reshtml = '''Content-Type: text/html\n >> >> >> >> Friends CGI Demo (dynamic screen) >> >> >> >> Friends list for: %s >> >> Your name is: %s >> >> You have %s friends. >> >> ''' >> >> >> >> form = cgi.FieldStorage() >> >> who = form['person'].value >> >> howmany = form['howmany'].value >> >> print reshtml % (who, who, howmany) >> >> >> >> It gives me the following error: >> >> Traceback (most recent call last): >> >> File "C:\Cgi-bin\friends1.py", line 15, in >> >> who = form['person'].value >> >> File "C:\Python25\lib\cgi.py", line 567, in __getitem__ >> >> raise KeyError, key >> >> KeyError: 'person' >> >> >> >> I understand python is saying that there is no such a key in a directory. >> >> >> >> The HTML form looks like this. it is displayed correctly both in FF and IE >> >> >> >> >> >> >> >> Friends CGI Demo (static screen) >> >> >> >> Friends list for: NEW USER >> >> >> >> Enter your Name: >> >> >> >>How many friends do you have? >> >> 0 >> >>10 >> >>25 >> >>50 >> >>100 >> >> >> >> >> >> Thanks again, >> >> >> >> Aivars >> >> >> >> >> >> >> >> >> >> >> >> >> >> 2008/10/24 Kent Johnson <[EMAIL PROTECTED]>: >> >> > On Fri, Oct 24, 2008 at 10:25 AM, aivars <[EMAIL PROTECTED]> wrote: >> >> >> Hello, >> >> >> >> >> >> I am learning python. >> >> >> >> >> >> I start the python CGI server like this: >> >> >> >> >> >> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core >> >> >> Python Programming chapter 20.5) >> >> >> >> >> >> The server starts in command prompt on windows XP by answering: >> >> >> Serving HTTP on 0.0.0.0 port 8000... >> >> >> >> >> >> Next I want to run this simple CGI script (from Deitel Python How to >> >> >> Program chapter 6). it is supposed to print out current date and time >> >> >> in a browser >> >> > >> >> > The CGI script should me in a /cgi-bin subdirectory of the dir where >> >> > you run the script. The URL to run the CGI will then be something like >> >> > http:://localhost:8000/cgi-bin/myscript.py >> >> > >> >> > Kent >> >> > >> >> ___ >> >> Tutor maillist - Tutor@python.org >> >> http://mail.python.org/mailman/listinfo/tutor >> > >> > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with simple python CGI script
It does not work neither as script or from command line. I will try to find the guy Wesley Chun and ask him 2008/10/25 John Pomni <[EMAIL PROTECTED]>: > Hi, > > The script does not work from command line but I guess you do not have > any problems running it as CGI? > > I like cgitb modules for debugging purposes very much. > > http://www.python.org/doc/2.5.2/lib/node566.html > > Jan > > On Fri, 2008-10-24 at 18:55 +0300, aivars wrote: >> Thanks very much, Kent, >> >> So it seems that directory /cgi-bin should be a subdirectory to that >> directory from which the web server was started/is running. That >> worked and Deitel's script - getting time displayed finally worked. >> >> still banging mu head with Wesley Chun's simple example - >> >> #!C:\python25\python.exe >> >> import cgi >> >> reshtml = '''Content-Type: text/html\n >> >> Friends CGI Demo (dynamic screen) >> >> Friends list for: %s >> Your name is: %s >> You have %s friends. >> ''' >> >> form = cgi.FieldStorage() >> who = form['person'].value >> howmany = form['howmany'].value >> print reshtml % (who, who, howmany) >> >> It gives me the following error: >> Traceback (most recent call last): >> File "C:\Cgi-bin\friends1.py", line 15, in >> who = form['person'].value >> File "C:\Python25\lib\cgi.py", line 567, in __getitem__ >> raise KeyError, key >> KeyError: 'person' >> >> I understand python is saying that there is no such a key in a directory. >> >> The HTML form looks like this. it is displayed correctly both in FF and IE >> >> >> >> Friends CGI Demo (static screen) >> >> Friends list for: NEW USER >> >> Enter your Name: >> >>How many friends do you have? >> 0 >>10 >>25 >>50 >>100 >> >> >> Thanks again, >> >> Aivars >> >> >> >> >> >> >> 2008/10/24 Kent Johnson <[EMAIL PROTECTED]>: >> > On Fri, Oct 24, 2008 at 10:25 AM, aivars <[EMAIL PROTECTED]> wrote: >> >> Hello, >> >> >> >> I am learning python. >> >> >> >> I start the python CGI server like this: >> >> >> >> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core >> >> Python Programming chapter 20.5) >> >> >> >> The server starts in command prompt on windows XP by answering: >> >> Serving HTTP on 0.0.0.0 port 8000... >> >> >> >> Next I want to run this simple CGI script (from Deitel Python How to >> >> Program chapter 6). it is supposed to print out current date and time >> >> in a browser >> > >> > The CGI script should me in a /cgi-bin subdirectory of the dir where >> > you run the script. The URL to run the CGI will then be something like >> > http:://localhost:8000/cgi-bin/myscript.py >> > >> > Kent >> > >> ___ >> Tutor maillist - Tutor@python.org >> http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help with simple python CGI script
Thanks very much, Kent, So it seems that directory /cgi-bin should be a subdirectory to that directory from which the web server was started/is running. That worked and Deitel's script - getting time displayed finally worked. still banging mu head with Wesley Chun's simple example - #!C:\python25\python.exe import cgi reshtml = '''Content-Type: text/html\n Friends CGI Demo (dynamic screen) Friends list for: %s Your name is: %s You have %s friends. ''' form = cgi.FieldStorage() who = form['person'].value howmany = form['howmany'].value print reshtml % (who, who, howmany) It gives me the following error: Traceback (most recent call last): File "C:\Cgi-bin\friends1.py", line 15, in who = form['person'].value File "C:\Python25\lib\cgi.py", line 567, in __getitem__ raise KeyError, key KeyError: 'person' I understand python is saying that there is no such a key in a directory. The HTML form looks like this. it is displayed correctly both in FF and IE Friends CGI Demo (static screen) Friends list for: NEW USER Enter your Name: How many friends do you have? 0 10 25 50 100 Thanks again, Aivars 2008/10/24 Kent Johnson <[EMAIL PROTECTED]>: > On Fri, Oct 24, 2008 at 10:25 AM, aivars <[EMAIL PROTECTED]> wrote: >> Hello, >> >> I am learning python. >> >> I start the python CGI server like this: >> >> python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core >> Python Programming chapter 20.5) >> >> The server starts in command prompt on windows XP by answering: >> Serving HTTP on 0.0.0.0 port 8000... >> >> Next I want to run this simple CGI script (from Deitel Python How to >> Program chapter 6). it is supposed to print out current date and time >> in a browser > > The CGI script should me in a /cgi-bin subdirectory of the dir where > you run the script. The URL to run the CGI will then be something like > http:://localhost:8000/cgi-bin/myscript.py > > Kent > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] please help with simple python CGI script
Hello, I am learning python. I start the python CGI server like this: python -m CGIHTTPServer (this syntax I saw in Wesley Chun's Core Python Programming chapter 20.5) The server starts in command prompt on windows XP by answering: Serving HTTP on 0.0.0.0 port 8000... Next I want to run this simple CGI script (from Deitel Python How to Program chapter 6). it is supposed to print out current date and time in a browser #!C:\python25\python.exe import time def printHeader(title): print """Content-type: text/html http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";> http://www.w3.org/1999/xhtml"; > %s """ % title printHeader("Current date and time") print time.ctime(time.time()) print "" And The server prints the script text in the browser. It does not run the script. The server response is 200. The script itself runs OK if being run from python/command line I also could not run the script from wesley chun's book. I think also because it seems the python cgi web server does not understand that it should run the script and not to print it out in web browser I am using python 2.5 on windows XP. What I am missing? Thanks Aivars ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor