|
From: Francisco C. <fra...@gm...> - 2013-09-12 17:07:56
|
Hello,
I have a question related with the connections. I am using the
following code for that:
try:
connection = connectionForURI('postgres://'+user+':'+password+'@
'+host+'/'+database)
sqlhub.processConnection = connection
connection.query("SELECT 1")
except OperationalError:
print "error"
but, I don't know if the error is because the user and password are wrong
or the sever is not working. How can I verify that? for example, maybe,
with a error code but I don't know how to get it.
Cheers,
|
|
From: Oleg B. <ph...@ph...> - 2013-09-12 17:16:00
|
Hi!
On Thu, Sep 12, 2013 at 02:07:48PM -0300, Francisco Chiotta <fra...@gm...> wrote:
> Hello,
> I have a question related with the connections. I am using the
> following code for that:
>
> try:
> connection = connectionForURI('postgres://'+user+':'+password+'@
> '+host+'/'+database)
> sqlhub.processConnection = connection
> connection.query("SELECT 1")
> except OperationalError:
> print "error"
>
> but, I don't know if the error is because the user and password are wrong
> or the sever is not working. How can I verify that? for example, maybe,
> with a error code but I don't know how to get it.
Hope this helps:
except OperationalError, e:
print "error:", e
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Francisco C. <fra...@gm...> - 2013-09-12 18:33:45
|
Thank you, but I need to distinguish the errors in the except statement,
something like that:
try:
connection = connectionForURI('postgres://'+user+':'+password+'@
'+host+'/'+database?debug=True)
sqlhub.processConnection = connection
connection.query("SELECT 1")
except OperationalError, e:
if (user or password are incorrect):
show a message
elif (the server is not working):
to do another thing
...
How can I ask the OperationalError object 'e' to do that?
2013/9/12 Daniel Monteiro Basso <dan...@gm...>
> Add ?*debug*=True to the connection URL. Also, instead of adding strings,
> consider formatting one, such as:
> connection = connectionForURI('postgres://{user}:{password}@
> {host}/{database}?*debug*=True'.format(locals()))
>
> Cheers,
>
> Daniel
>
>
> On Thu, Sep 12, 2013 at 6:07 PM, Francisco Chiotta <fra...@gm...>wrote:
>
>> Hello,
>> I have a question related with the connections. I am using the
>> following code for that:
>>
>> try:
>> connection = connectionForURI('postgres://'+user+':'+password+'@
>> '+host+'/'+database)
>> sqlhub.processConnection = connection
>> connection.query("SELECT 1")
>> except OperationalError:
>> print "error"
>>
>> but, I don't know if the error is because the user and password are wrong
>> or the sever is not working. How can I verify that? for example, maybe,
>> with a error code but I don't know how to get it.
>>
>> Cheers,
>>
>>
>>
>> ------------------------------------------------------------------------------
>> How ServiceNow helps IT people transform IT departments:
>> 1. Consolidate legacy IT systems to a single system of record for IT
>> 2. Standardize and globalize service processes across IT
>> 3. Implement zero-touch automation to replace manual, redundant tasks
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
>> _______________________________________________
>> sqlobject-discuss mailing list
>> sql...@li...
>> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>>
>>
>
|
|
From: Oleg B. <ph...@ph...> - 2013-09-12 18:56:21
|
On Thu, Sep 12, 2013 at 03:33:36PM -0300, Francisco Chiotta <fra...@gm...> wrote:
> Thank you, but I need to distinguish the errors in the except statement,
> something like that:
>
> try:
> connection = connectionForURI('postgres://'+user+':'+password+'@
> '+host+'/'+database?debug=True)
> sqlhub.processConnection = connection
> connection.query("SELECT 1")
> except OperationalError, e:
> if (user or password are incorrect):
> show a message
> elif (the server is not working):
> to do another thing
> ...
>
> How can I ask the OperationalError object 'e' to do that?
I don't think database drivers provide such information. You can try
to parse the error message, but they are very database- and
locale-dependent.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Francisco C. <fra...@gm...> - 2013-09-12 19:43:19
|
Ok, I thought that It was possible to recover an error code or something
like that.
Thank you for your help.
2013/9/12 Oleg Broytman <ph...@ph...>
> On Thu, Sep 12, 2013 at 03:33:36PM -0300, Francisco Chiotta <
> fra...@gm...> wrote:
> > Thank you, but I need to distinguish the errors in the except statement,
> > something like that:
> >
> > try:
> > connection = connectionForURI('postgres://'+user+':'+password+'@
> > '+host+'/'+database?debug=True)
> > sqlhub.processConnection = connection
> > connection.query("SELECT 1")
> > except OperationalError, e:
> > if (user or password are incorrect):
> > show a message
> > elif (the server is not working):
> > to do another thing
> > ...
> >
> > How can I ask the OperationalError object 'e' to do that?
>
> I don't think database drivers provide such information. You can try
> to parse the error message, but they are very database- and
> locale-dependent.
>
> Oleg.
> --
> Oleg Broytman http://phdru.name/ ph...@ph...
> Programmers don't die, they just GOSUB without RETURN.
>
>
> ------------------------------------------------------------------------------
> How ServiceNow helps IT people transform IT departments:
> 1. Consolidate legacy IT systems to a single system of record for IT
> 2. Standardize and globalize service processes across IT
> 3. Implement zero-touch automation to replace manual, redundant tasks
> http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
> _______________________________________________
> sqlobject-discuss mailing list
> sql...@li...
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>
|
|
From: Oleg B. <ph...@ph...> - 2013-09-12 20:12:47
|
On Thu, Sep 12, 2013 at 04:43:09PM -0300, Francisco Chiotta <fra...@gm...> wrote: > Ok, I thought that It was possible to recover an error code or something > like that. psycopg2 provides some information: http://initd.org/psycopg/docs/module.html#exceptions http://initd.org/psycopg/docs/errorcodes.html#module-psycopg2.errorcodes but SQLObject loose that information when it converts psycopg2's exceptions to SQLObject's exceptions. I can try to extract that information but only for SQLObject 1.5 (which is currently in pre-release state) and only for Postgres/psycopg2 (PySQLite doesn't return error codes, only strings; exceptions from MySQL already provide error code in e.code attribute). Do you want me to provide e.code for psycopg2? I'll ask you to test the result. Oleg. -- Oleg Broytman http://phdru.name/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
|
From: Francisco C. <fra...@gm...> - 2013-09-13 14:40:17
|
It would be great. Sure, I can test the results. Cheers 2013/9/12 Oleg Broytman <ph...@ph...> > On Thu, Sep 12, 2013 at 04:43:09PM -0300, Francisco Chiotta < > fra...@gm...> wrote: > > Ok, I thought that It was possible to recover an error code or something > > like that. > > psycopg2 provides some information: > http://initd.org/psycopg/docs/module.html#exceptions > http://initd.org/psycopg/docs/errorcodes.html#module-psycopg2.errorcodes > but SQLObject loose that information when it converts psycopg2's > exceptions to SQLObject's exceptions. I can try to extract that > information but only for SQLObject 1.5 (which is currently in > pre-release state) and only for Postgres/psycopg2 (PySQLite doesn't > return error codes, only strings; exceptions from MySQL already provide > error code in e.code attribute). > Do you want me to provide e.code for psycopg2? I'll ask you to test > the result. > > Oleg. > -- > Oleg Broytman http://phdru.name/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > > > ------------------------------------------------------------------------------ > How ServiceNow helps IT people transform IT departments: > 1. Consolidate legacy IT systems to a single system of record for IT > 2. Standardize and globalize service processes across IT > 3. Implement zero-touch automation to replace manual, redundant tasks > http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
|
From: Oleg B. <ph...@ph...> - 2013-09-13 15:00:51
|
On Fri, Sep 13, 2013 at 11:40:09AM -0300, Francisco Chiotta <fra...@gm...> wrote:
> It would be great. Sure, I can test the results.
>
> 2013/9/12 Oleg Broytman <ph...@ph...>
> > Do you want me to provide e.code for psycopg2? I'll ask you to test
> > the result.
I will try to do that before taking a vacation next week. If not --
I'll be back at the 28th of September.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Oleg B. <ph...@ph...> - 2013-09-15 13:52:35
Attachments:
pgcode.patch
|
On Fri, Sep 13, 2013 at 11:40:09AM -0300, Francisco Chiotta <fra...@gm...> wrote:
> It would be great. Sure, I can test the results.
The patch is attached. The code and error string are available:
try:
do_something()
except OperationalError, e:
print e.args[0].code
print e.args[0].error
Doesn't work for me, though -- pgcode/pgerror are always None.
Perhaps I'm using old version of psycopg2 -- 2.4.5.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Francisco C. <fra...@gm...> - 2013-09-26 14:52:19
|
It doesn't work for me either. I have installed the psycopg 2.5.1 (the latest), and I always get None if the authentication fails or the server is not working in the given IP. I don't know why. 2013/9/15 Oleg Broytman <ph...@ph...> > On Fri, Sep 13, 2013 at 11:40:09AM -0300, Francisco Chiotta < > fra...@gm...> wrote: > > It would be great. Sure, I can test the results. > > The patch is attached. The code and error string are available: > > try: > do_something() > except OperationalError, e: > print e.args[0].code > print e.args[0].error > > Doesn't work for me, though -- pgcode/pgerror are always None. > Perhaps I'm using old version of psycopg2 -- 2.4.5. > > Oleg. > -- > Oleg Broytman http://phdru.name/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > |
|
From: Oleg B. <ph...@ph...> - 2013-09-28 09:22:48
|
Hi!
On Thu, Sep 26, 2013 at 11:52:08AM -0300, Francisco Chiotta <fra...@gm...> wrote:
> It doesn't work for me either. I have installed the psycopg 2.5.1 (the
> latest), and I always get None if the authentication fails or the server is
> not working in the given IP. I don't know why.
>
> 2013/9/15 Oleg Broytman <ph...@ph...>
>
> > On Fri, Sep 13, 2013 at 11:40:09AM -0300, Francisco Chiotta <
> > fra...@gm...> wrote:
> > > It would be great. Sure, I can test the results.
> >
> > The patch is attached. The code and error string are available:
> >
> > try:
> > do_something()
> > except OperationalError, e:
> > print e.args[0].code
> > print e.args[0].error
> >
> > Doesn't work for me, though -- pgcode/pgerror are always None.
> > Perhaps I'm using old version of psycopg2 -- 2.4.5.
I returned from the vacation. Will test if psycopg w/o SQLObject
returns the code/error.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Oleg B. <ph...@ph...> - 2013-09-30 13:52:06
|
On Sat, Sep 28, 2013 at 01:22:26PM +0400, Oleg Broytman <ph...@ph...> wrote:
> I returned from the vacation. Will test if psycopg w/o SQLObject
> returns the code/error.
The following program:
from decimal import Decimal
import psycopg2
def report_error(e):
print e.__class__.__name__, e.pgcode, e.pgerror
raise SystemExit
try:
con = psycopg2.connect(database="test")
except psycopg2.Error, e:
report_error(e)
cur = con.cursor()
try:
cur.execute('SELECT * FROM test ORDER BY id')
except psycopg2.Error, e:
report_error(e)
prints
OperationalError None None
when it cannot connect to the database and prints
ProgrammingError 42P01 ERROR: relation "test" does not exist
when the database exists but there is no table "test". I.e., psycopg2
doesn't return proper code/message for an OperationalError, so your
original request cannot be fullfilled, alas. You can ask psycopg2
authors if they are going to fix that.
I will do more tests and include the code into the next release. I
hope to release SQLObject 1.5 RSN.
Oleg.
--
Oleg Broytman http://phdru.name/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|
|
From: Francisco C. <fra...@gm...> - 2013-10-10 17:17:24
|
Thank you for your help, I am going to ask psycopg team about the problem.
If I have some news about how to fix it, i will tell you.
Cheers.
2013/9/30 Oleg Broytman <ph...@ph...>
> On Sat, Sep 28, 2013 at 01:22:26PM +0400, Oleg Broytman <ph...@ph...>
> wrote:
> > I returned from the vacation. Will test if psycopg w/o SQLObject
> > returns the code/error.
>
> The following program:
>
> from decimal import Decimal
> import psycopg2
>
> def report_error(e):
> print e.__class__.__name__, e.pgcode, e.pgerror
> raise SystemExit
>
> try:
> con = psycopg2.connect(database="test")
> except psycopg2.Error, e:
> report_error(e)
>
> cur = con.cursor()
>
> try:
> cur.execute('SELECT * FROM test ORDER BY id')
> except psycopg2.Error, e:
> report_error(e)
>
> prints
>
> OperationalError None None
>
> when it cannot connect to the database and prints
>
> ProgrammingError 42P01 ERROR: relation "test" does not exist
>
> when the database exists but there is no table "test". I.e., psycopg2
> doesn't return proper code/message for an OperationalError, so your
> original request cannot be fullfilled, alas. You can ask psycopg2
> authors if they are going to fix that.
>
> I will do more tests and include the code into the next release. I
> hope to release SQLObject 1.5 RSN.
>
> Oleg.
> --
> Oleg Broytman http://phdru.name/ ph...@ph...
> Programmers don't die, they just GOSUB without RETURN.
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
> from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
> _______________________________________________
> sqlobject-discuss mailing list
> sql...@li...
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>
|