Python scripts - DB connection question...
Hi there, I haven't used Zope for a few months - I'm now using Python scripts instead of the Python method product. They don't appear to be too dissimilar, but I'm having a little trouble trying to execute an SQL query from a script. In a Python method it would be something like: db_conn = self.Gadfly_database_connection() // generate SQL result=db_conn.query(updatePersonSQL) This doesn't work in a script though. Could someone how to estabish a connection and execute a query? Thanks in advance. - Best regards, Lee
I would have thought that the only change would need to be to change 'self' to 'context'. ----- Original Message ----- From: "Lee" <lee.reilly@ntlworld.com> To: <zope@zope.org> Sent: Wednesday, July 04, 2001 10:49 PM Subject: [Zope] Python scripts - DB connection question...
Hi there,
I haven't used Zope for a few months - I'm now using Python scripts instead of the Python method product. They don't appear to be too dissimilar, but I'm having a little trouble trying to execute an SQL query from a script. In a Python method it would be something like:
db_conn = self.Gadfly_database_connection() // generate SQL result=db_conn.query(updatePersonSQL)
This doesn't work in a script though. Could someone how to estabish a connection and execute a query?
Thanks in advance.
- Best regards,
Lee
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Phil Harris wrote:
I would have thought that the only change would need to be to change 'self' to 'context'.
Thanks Phil, but I've still got some problems. I'm using Zope on the NipLtd server... The script appears to be connecting okay (well, it doesn't result in an error), but when I try and execute the SQL I am asked for my user/auth again, which isn't recognised and gives the following error: result=db_conn.query(updatePersonSQL) => +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Unauthorized Sorry, a Zope error occurred. Traceback (innermost last): File /usr/local/zope/2.3.2_base/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /usr/local/zope/2.3.2_base/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/zope/2.3.2_base/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/zope/2.3.2_base/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: processData) File /usr/local/zope/2.3.2_base/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: processData) File /usr/local/zope/2.3.2_base/lib/python/Shared/DC/Scripts/Bindings.py, line 324, in __call__ (Object: processData) File /usr/local/zope/2.3.2_base/lib/python/Shared/DC/Scripts/Bindings.py, line 354, in _bindAndExec (Object: processData) File /usr/local/zope/2.3.2_base/lib/python/Products/PythonScripts/PythonScript.py, line 336, in _exec (Object: processData) (Info: ({'script': <PythonScript instance at be96aa8>, 'context': <Folder instance at b1ddc48>, 'container': <Folder instance at b1ddc48>, 'traverse_subpath': []}, ('1', '3', '2'), {}, None)) File Script (Python), line 14, in processData File /usr/local/zope/2.3.2_base/lib/python/Products/PythonScripts/Guarded.py, line 273, in __getattr__ File /usr/local/zope/2.3.2_base/lib/python/Products/PythonScripts/Guarded.py, line 150, in __careful_getattr__ File /usr/local/zope/2.3.2_base/lib/python/AccessControl/SecurityManager.py, line 144, in validate File /usr/local/zope/2.3.2_base/lib/python/AccessControl/ZopeSecurityPolicy.py, line 168, in validate Unauthorized: query +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Does anyone have any idea what's wrong? Cheers, Lee
From: "Lee" <lee.reilly@ntlworld.com>
The script appears to be connecting okay (well, it doesn't result in an error), but when I try and execute the SQL I am asked for my user/auth again, which isn't recognised and gives the following error:
result=db_conn.query(updatePersonSQL) =>
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Unauthorized
There's no permission or other security declaration on the connection's query() method, so Zope security prevents you from calling it. You can edit the DB code to add security, or write an External Method that takes a connection and returns its query method (and possibly its sql_quote method as well, if you need it). Cheers, Evan @ digicool & 4-am
participants (3)
-
Evan Simpson -
Lee -
Phil Harris