Hi all
Below is the text of a message I was about to send in connection with
an obscure problem. I have now almost got to the bottom of it, and am
fairly confident that it is a bug in pyPgSQL. I hope this is the
correct place to report such bugs. If not, please advise the correct
forum.
I have left the original message intact as it provides important
information. At the bottom, I have recorded the new information that I
have discovered.
-------------------------------------------------------------------------------
Here is an obscure problem. I am not sure if I can explain the
symptoms properly, but I will do my best.
I have a Linux box (RH9) and an MSW box (W2K Pro) networked to each
other. Both are running Python 2.3.3.
Linux is the server. It is running PostgreSQL, which listens on port
5432. It is also running a socket server program that I have written
using socket.socket() , listening on port 6543. I am using pyPgSQL to
connect to the database.
MSW is the client. From time to time it sends messages to my socket
server. Messages are strings consisting of a single digit identifier,
followed by a cPickle'd tuple containing various data fields. The
client uses cPickle.dumps to prepare the string before sending, and
the server uses cPickle.loads to unpickle it after receiving.
Most times it works perfectly, but in one particular situation the
server terminates with an error. The error is consistent - it always
gives the same error resulting from the same message. However, I do
not think it is caused by the message itself, as exactly the same
message is sent in different circumstances without generating an
error.
The traceback is as follows -
File "./chag_server.py" , line 190, in ?
dat = cPickle.loads(d ata[1:])
File "/usr/local/lib/python2.3/site-packages/pyPgSQL/libpq/__init__.py",
line 43, in _I8
return PgInt8(value)
NameError: ("global name 'PgInt8' is not defined", <function _I8
at 0x403a04c4>, ('17',))
The error occurs at the point of unpickling - I have moved this
around, and it always fails at this point.
A typical example of the tuple being unpickled is (2,'Ar',17,1) - it
is all normal strings and integers.
I have no idea why pyPgSQL is involved at all - I am certainly not
invoking it directly. In fact the error comes from my server program,
and that does not even import pyPgSQL.
Here are the relevant lines from pyPgSQL/libpq/__init__.py -
from libpq import *
from libpq import __version__
HAVE_LONG_LONG_ SUPPORT = dir().count('Pg Int8') == 1
#---------------------------------------------------------------+
# Add support to pickle the following pyPgSQL objects: |
# PgInt2, PgInt8, PgBoolean |
#---------------------------------------------------------------+
def _B(value):
return PgBoolean(value )
def _I2(value):
return PgInt2(value)
def _I8(value):
return PgInt8(value)
Somehow pyPgSQL is responding to my unpickling command, and raising an
error because PgInt8 is not defined.
Here is another fact, which may provide a clue or may add confusion.
If I run exactly the same program from the Linux box, using it as the
client as well as the server, the error does not appear. I connect via
the external IP address, not via 127.0.0.1, so I would have thought it
would behave the same, but it does not.
-------------------------------------------------------------------------------
Ok, here is the reason. I mentioned above that a typical tuple
consists of (2,'Ar',17,1). I have found that under some circumstances
the 3rd element is of type 'long' instead of type 'int', and this is
what generates the error.
Whether it is a long or an int is determined by pyPgSQL itself. It is
a column value, where the column is of type 'serial', which means that
PostgreSQL will generate a next number if the row is being inserted.
If the row exists, the column value is returned along with all the
other columns, and is returned as type int. If the row does not exist,
I insert it, and then to retrieve the id generated, I have the
following piece of code -
cur = db.cursor()
cur.execute("se lect currval('%s_%s_ Seq')" % (tableid,column id) )
rowid = cur.fetchone()[0]
In this case, rowid contains the correct value, but is of type long.
So this raises various questions -
Why is PgInt8 not defined?
Why does pyPgSQL affect my server program, which does not import any
of pyPgSQL?
Why does the error only occur when I connect from a remote machine?
Now that I have identified the problem, I can work around it, so this
has become a matter of correctness rather than a matter of urgency.
For those that have read this far, thanks for your patience.
Frank Millman 2 1386
On 6 Aug 2004 00:31:39 -0700, fr***@chagford. com (Frank Millman)
declaimed the following in comp.lang.pytho n: Somehow pyPgSQL is responding to my unpickling command, and raising an error because PgInt8 is not defined.
I'd suspect the pickled data itself has a reference to the
PgInt8(), AND I'd suspect that is an OS-dependent function -- did you
notice that pseudo-constant about HAVE_LONG_LONG. ..?
Here is another fact, which may provide a clue or may add confusion. If I run exactly the same program from the Linux box, using it as the client as well as the server, the error does not appear. I connect via the external IP address, not via 127.0.0.1, so I would have thought it would behave the same, but it does not.
Which would be reasonable if the changed OS doesn't use/need
PgInt8() when it does the pickling. Why is PgInt8 not defined?
Because the OS/compiler may have supported the data type
natively?
Why does pyPgSQL affect my server program, which does not import any of pyPgSQL?
Hypothesis: The pickled object includes a reference to the
data-type?
Why does the error only occur when I connect from a remote machine?
See comment regarding definition...
-- =============== =============== =============== =============== == < wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG < wu******@dm.net | Bestiaria Support Staff < =============== =============== =============== =============== == < Home Page: <http://www.dm.net/~wulfraed/> < Overflow Page: <http://wlfraed.home.ne tcom.com/> <
Frank Millman wrote: Hi all
Below is the text of a message I was about to send in connection with an obscure problem. I have now almost got to the bottom of it, and am fairly confident that it is a bug in pyPgSQL. I hope this is the correct place to report such bugs. If not, please advise the correct forum. [...]
Please file a bug on the pyPgSQL bug tracker on Sourceforge. This way,
it's less likely that this will get lost: http://sourceforge.net/projects/pypgsql
-- Gerhard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paolo Alexis Falcone |
last post by:
Whenever I try to access a table with many rows using PgSQL's
fetchall(), this happens:
>>> from pyPgSQL import PgSQL
>>> db = PgSQL.connect("192.168.0.8:5432:whitegold","dondon","dondon")
>>> PgSQL.NoPostgresCursor = 1
>>> cur = db.cursor()
>>> cur.execute("SELECT * FROM customer")
>>> data = cur.fetchall()
Traceback (most recent call last):
|
by: Timo Virkkala |
last post by:
Hello.
I'm having some trouble with getting the pyPgSQL module to work. I
installed it and the mxDateTime module into my local directory (I'm
doing this on my university's server and I don't have access to /usr).
When I try to import it I get the following error:
>>> from pyPgSql import libpq
Traceback (most recent call last):
File "<stdin>", line 1, in ?
|
by: Rene Pijlman |
last post by:
I can't seem to find any way to specify the character encoding with the DB
API implementation of PyPgSQL. There is no mention of encoding and Unicode
in the DB API v2.0 spec and the PyPgSQL README.
When I have Unicode strings in Python and store it in a PostgreSQL Unicode
database, will the data automatically be correctly encoded? Or do I need
to specify the UTF-8 client encoding on the database connection somehow?
I'm using the...
|
by: Batista, Facundo |
last post by:
I'm doing a small program, in which the user will have the option to enter
his/her password everytime, or just save it (to a file).
So, is there a module to obscure the password text in a secure way?
I can't hash it (with md5 or something), because I not need to compare the
password the user enters with a previous one.
I need to restore the password later and use it as if the user just entered
it.
|
by: J Dubal |
last post by:
Hello good people,
Following works in FC1 (python-2.2.3-7, postgresql-7.3.4-11,
kernel-2.4.22-1.2194.nptl, pyPgSQL-2.4)
from pyPgSQL import PgSQL
conn = PgSQL.connect('localhost',database='rop')
loccur = conn.cursor()
loccur.execute("DECLARE itemcursor CURSOR FOR \
SELECT * FROM locmf")
| |
by: Gurpreet Sachdeva |
last post by:
I am using Redhat 9.0/python2.3. I installed pyPgSQL-2.4.tar.gz and it
was successfull. Now when I am trying to import that module, I got:
Python 2.3.3 (#1, Jan 11 2005, 15:24:09)
on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyPgSQL import PgSQL
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "pyPgSQL/PgSQL.py", line 391, in ?
|
by: Andrew Poulos |
last post by:
I've built a javascript driven quiz. Given that client-side scripting is
not secure, is there a way to "obscure" answers so that they are
unavailable to the casual viewer? For example, If I have an external js
answer file with this in it:
quest = ;
is there a way to "obscure" the value but still allow js to reveal it.
What I'm looking for, I guess, is some algorithm that works like this:
// Massage the answers
|
by: Tin Gherdanarra |
last post by:
Hallo,
I'm trying to install pypgsql. However, I get syntax errors
while compiling the C sources. The following excerpt
from pgconnection.h looks a little funny to me:
typedef struct {
PyObject_HEAD /* Here is the syntax error, and rightly so */
PGconn *conn;
PyObject *host;
|
by: Eric |
last post by:
Hey guys,
Has anyone seen this error when installing trac? The problem seems
related to pyPgSQL, which is installed. (Although I had to go in and
add some headers to make it work)
Templates directory >
Creating and Initializing Project
Failed to create environment.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |