[Tutor] Tutor Digest, Vol 116, Issue 4

Ismar Sehic i.sheeha at gmail.com
Tue Oct 1 12:16:20 CEST 2013


great, thanks for the quick reply, Walter.i will follow your advice and see
what happens.:)


On Tue, Oct 1, 2013 at 12:00 PM, <tutor-request at python.org> wrote:

> Send Tutor mailing list submissions to
>         tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request at python.org
>
> You can reach the person managing the list at
>         tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. Re: sqlite3 COMMIT directive (Tim Golden)
>    2. Re: sqlite3 COMMIT directive (Mark Lawrence)
>    3. Re: soappy, soap, xml ..fuss (Walter Prins)
>    4. Re: sqlite3 COMMIT directive (Alex Kleider)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 01 Oct 2013 09:25:14 +0100
> From: Tim Golden <mail at timgolden.me.uk>
> To: tutor at python.org
> Subject: Re: [Tutor] sqlite3 COMMIT directive
> Message-ID: <524A86EA.6000701 at timgolden.me.uk>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On 01/10/2013 09:03, Alan Gauld wrote:
> > You don't normally need to use COMMIT when programming SQLite from
> > Python, the database starts and ends transactions automatically from
> > within the execute() function. You only need to manually commit if you
> > manually create the transaction using BEGIN...
>
> Not so, I'm afraid. If you want autocommit, you need to send an
> isolation_level of None to the .connect function. If you don't, the
> database will rollback any uncommitted transactions on exit.
>
> The code below will only output (1,) as that value was committed. The
> later row is lost when the cursor/db closes.
>
> <code>
> import os, sys
> import sqlite3
>
> dbname = "no-commit.db"
> if os.path.exists(dbname):
>     os.unlink(dbname)
>
> db = sqlite3.connect(dbname)
> q = db.cursor()
> q.execute("CREATE TABLE test(a INT)")
> q.execute("INSERT INTO test(a) VALUES (1)")
> db.commit()
> q.execute("INSERT INTO test(a) VALUES (2)")
> q.close()
> db.close()
>
> db = sqlite3.connect(dbname)
> q = db.cursor()
> for row in q.execute("SELECT * FROM test").fetchall():
>     print(row)
> q.close()
> db.close()
>
> </code>
>
>
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 01 Oct 2013 09:40:07 +0100
> From: Mark Lawrence <breamoreboy at yahoo.co.uk>
> To: tutor at python.org
> Subject: Re: [Tutor] sqlite3 COMMIT directive
> Message-ID: <l2e1p1$kuo$1 at ger.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 01/10/2013 04:16, Alex Kleider wrote:
> >              try:
> >                  cur.execute("COMMIT;")
> >              except:
> >                  pass
> >
> > And the problem = \
> > """
> > If the 'cur.execute("COMMIT;")' statement is left by itself, outside of a
> > "try/except" clause, I get an error with the following trace back:
> > "
> > Traceback (most recent call last):
> >    File "./uwomeds68.py", line 119, in <module>
> >      go_on.insert()
> >    File "./uwomeds68.py", line 64, in insert
> >      cur.execute("COMMIT;")
> > sqlite3.OperationalError: cannot commit - no transaction is active
> > "
> >
>
> As you've already had some sound advice I'd just like to point out that
> a bare except is considered bad form, e.g. it would mask any attempt to
> use CTRL-C to halt a rouge program that's inadvertantly gone into an
> infinite loop.  An obvious one to use here could be the given
> sqlite3.OperationalError.  Common problems that are caught include
> NameError, IndexError and ScrewedUpCompletelyError :)
>
> --
> Cheers.
>
> Mark Lawrence
>
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 1 Oct 2013 10:42:57 +0100
> From: Walter Prins <wprins at gmail.com>
> Cc: python mail list <tutor at python.org>
> Subject: Re: [Tutor] soappy, soap, xml ..fuss
> Message-ID:
>         <
> CANLXbfA948X8ov7tPBVMXi-x-kiYav9Y0JfmWCJPu233dRpPjQ at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
>
> On 1 October 2013 09:08, Ismar Sehic <i.sheeha at gmail.com> wrote:
>
> > hello, it's me again with my stubborn soap and xml request.please take a
> > look at this code and the output, just tell if i'm missing something - i
> > don't get it.
> >
> >>   File "/usr/lib/python2.6/socket.py", line 514, in create_connection
> >>     raise error, msg
> >> socket.error: [Errno 110] Connection timed out
> >>
> >
> > what could cause this socket error?
> >
>
> You're getting a generic socket error.  This implies the website/web
> service might be down, or that the address you're using to contact it is in
> fact incorrect.  (Or, your computer might not be connected to the internet,
> but I'm pretty sure that's not the problem here ;) )
>
>
> > and what is this Deprecation Warning?
> >
>
> It's some sort of internal deprecation warning in SOAPpy, you can probably
> ignore it for now.
>
>
>
> > i don't get it anymore, i tried all the possible ways - with simple http
> > request i get an internal server error [500].i wrote an email to the
> people
> > at hotelbeds services 7 days ago, still waiting for the reply.how do i
> make
> > this API, i cannot get simple xml request through.
> >
>
> You're still messing with manually constructing XML requests to feed to the
> SOAP service.  Don't do that.  The entire point of libraries like SOAPpy
> and ZSI is to mostly shield your from all the XML under the hood.  That
> said, as mentioned before, it seems to me you have more fundamental issues
> here, e.g. contacting/talking to the web service.  You should be able to
> paste for example the WSDL URL into your browser and get the WSDL document
> displayed in your browser.  If you can't even do that, then it obviously
> won't work when you try to contact the same URL via your program.
>
> I'd suggest you go find a working web service, and experiment interfacing
> with that first.  You can hopefully find some to work with here:
> http://www.webservicex.net/WS/wscatlist.aspx
>
> Once you've got some confidence working with a simple working web service
> using SOAPpy, you should return to this problem.  You should be able to
> introspect the Python API provided to you from the webservice directly
> using the Python interpreter, and then directly call the web service
> methods, with zero manual construction of XML required.  See these pages:
> http://www.diveintopython.net/soap_web_services/introspection.html
> http://users.skynet.be/pascalbotte/rcx-ws-doc/python.htm
>
> Walter
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20131001/ddf69198/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 4
> Date: Tue, 01 Oct 2013 02:57:03 -0700
> From: Alex Kleider <akleider at sonic.net>
> To: Python Tutor <tutor at python.org>
> Subject: Re: [Tutor] sqlite3 COMMIT directive
> Message-ID: <aa965151e69604e350f0287e737677ee at sonic.net>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> Thank you to respondents.
>
> That the code worked at all is something I don't understand.
> As Alan G pointed out, I had forgotten to include the "cur =
> con.cursor()" line.
> After this was corrected and the try/except statement deleted, it worked
> as I expected.
>
> Thanks to "-nick" for pointing me to the references regarding
> transactions.  That's not easy stuff.
> I was aware that 'bare except' statements are to be eschewed but now,
> thanks to Mark Lawrence, have a better idea of why.
>
> Much appreciated.
>
> alex
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> End of Tutor Digest, Vol 116, Issue 4
> *************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131001/af9a4651/attachment.html>


More information about the Tutor mailing list