How to pass a Z SQL method a variable from a Python Script?
This is probably a very basic question, but it's been stopping me for hours (very frustrating). I have a Python script that's trying to pass variables into a Z SQL method. In the Python script I wrote: container.send_to_database(CName, email, phone) where send_to_database is the Z SQL Method. send_to_database looks like this: Z SQL Method at /send_to_database Help! Title Connection Id MySQL_database_connection Arguments CName email phone insert into name_table (CName, email, phone) values ("<dtml-var CName>", "<dtml-var email>", "<dtml-var phone>"); Yet when I run the Python script, I get Zope Error Zope has encountered an error while publishing this resource. Error Type: KeyError Error Value: CName Am I passing the variables in the wrong way from the Python Script? Is there something wrong with the Z SQL method? In the Python script the variables CName, email, phone are well defined. Someone, anyone HELP! so I can actually do something besides look hopelessly at this error message for days on end.
While it's probably not obvious -- you should pass the parameters in by keyword rather than positionally. e.g. container.send_to_database(CName=CName, email=email, phone=phone) Additionally, I'd use <dtml-sqlvar CName type="string"> instead of "<dtml-var CName>" to get proper quoting. And as a last bit, SQL wants strings quoted with single quotes, not double quotes. Sage Mo wrote:
This is probably a very basic question, but it's been stopping me for hours (very frustrating).
I have a Python script that's trying to pass variables into a Z SQL method. In the Python script I wrote:
container.send_to_database(CName, email, phone)
where send_to_database is the Z SQL Method.
send_to_database looks like this:
Z SQL Method at /send_to_database Help!
Title Connection Id MySQL_database_connection Arguments CName email phone
insert into name_table (CName, email, phone) values ("<dtml-var CName>", "<dtml-var email>", "<dtml-var phone>");
Yet when I run the Python script, I get
Zope Error Zope has encountered an error while publishing this resource.
Error Type: KeyError Error Value: CName
Am I passing the variables in the wrong way from the Python Script? Is there something wrong with the Z SQL method? In the Python script the variables CName, email, phone are well defined. Someone, anyone HELP! so I can actually do something besides look hopelessly at this error message for days on end.
for starters, you should be using <dtml-zsqlvar ...> rather than <dtml-var ...>, for security. Then removing the quotes, so your method looks like: insert into name_table (CName, email, phone) values (<dtml-sqlvar CName type="string">, <dtml-sqlvar email type="string">, <dtml-sqlvar phone type="string">) then call using parameter names from the python script: context.send_to_database(CName=CName, email=email, phone=phone) does that work? HTH Ben Avery p.s. cute kitten Sage Mo wrote:
This is probably a very basic question, but it's been stopping me for hours (very frustrating).
I have a Python script that's trying to pass variables into a Z SQL method. In the Python script I wrote:
container.send_to_database(CName, email, phone)
where send_to_database is the Z SQL Method.
send_to_database looks like this:
Z SQL Method *Z SQL Method at / <http://www.heiropure.com/manage_workspace>send_to_database* Help! <http://www.heiropure.com/HelpSys?help_url=/Control_Panel/Products/ZSQLMethods/Help/Z-SQL-Method_Edit.stx>
Title Connection Id Arguments
Yet when I run the Python script, I get
Zope Error
Zope has encountered an error while publishing this resource.
*Error Type: KeyError* *Error Value: CName*
Am I passing the variables in the wrong way from the Python Script? Is there something wrong with the Z SQL method? In the Python script the variables CName, email, phone are well defined. Someone, anyone HELP! so I can actually do something besides look hopelessly at this error message for days on end.
You want to use container.send_to_database(CName=x, email=y, phone=z) or alternatively make sure that CName, email and phone are in the REQUEST. You also really should use <dtml-sqlvar> rather than <dtml-var> in your method, that all of the quoting that SQL needs gets done. A On 14/1/03 6:43 pm, "Sage Mo" <sagefmo@nc.rr.com> wrote:
This is probably a very basic question, but it's been stopping me for hours (very frustrating).
I have a Python script that's trying to pass variables into a Z SQL method. In the Python script I wrote:
container.send_to_database(CName, email, phone)
where send_to_database is the Z SQL Method.
send_to_database looks like this:
Z SQL Method at / <http://www.heiropure.com/manage_workspace> send_to_database Help! <http://www.heiropure.com/HelpSys?help_url=/Control_Panel/Products/ZSQLMethod... /Help/Z-SQL-Method_Edit.stx> Title
Connection Id MySQL_database_connection Arguments CName email phone insert into name_table (CName, email, phone) values ("<dtml-var CName>", "<dtml-var email>", "<dtml-var phone>");
Yet when I run the Python script, I get
Zope Error Zope has encountered an error while publishing this resource. Error Type: KeyError Error Value: CName Am I passing the variables in the wrong way from the Python Script? Is there something wrong with the Z SQL method? In the Python script the variables CName, email, phone are well defined. Someone, anyone HELP! so I can actually do something besides look hopelessly at this error message for days on end.
Hi Sage, --On Dienstag, 14. Januar 2003 13:43 -0500 Sage Mo <sagefmo@nc.rr.com> wrote:
This is probably a very basic question, but it's been stopping me for hours (very frustrating). I have a Python script that's trying to pass variables into a Z SQL method. In the Python script I wrote: container.send_to_database(CName, email, phone)
Just use named parameters (see python reference) container.send_to_database(CName=CName, email=email, phone=phone) the funny double naming comes from the fact your local variables happen to have the same name. This is not a must of course.
where send_to_database is the Z SQL Method.
send_to_database looks like this:
[Image: "Z"] Z SQL Method at /send_to_database Help!
Title
Connection Id MySQL_database_connection
Arguments CName email phone
insert into name_table (CName, email, phone) values ("<dtml-var CName>", "<dtml-var email>", "<dtml-var phone>"); Yet when I run the Python script, I get
This is very wrong and dangerous! I'd suggest you read the relevant section of the zope book again! Use insert into name_table (CName, email, phone) values (<dtml-sqlvar CName type=string>, <dtml-sqlvar email type=string>, <dtml-sqlvar phone type=string>) Which does the right quoting for you. Also any SQLxx complient database would complain about the double quoutes around your strings anyway. HTH Tino Wildenhain
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: KeyError Error Value: CName
Am I passing the variables in the wrong way from the Python Script? Is there something wrong with the Z SQL method? In the Python script the variables CName, email, phone are well defined. Someone, anyone HELP! so I can actually do something besides look hopelessly at this error message for days on end.
participants (6)
-
Andrew Veitch -
Ben Avery -
Kevin Carlson -
Matthew T. Kromer -
Sage Mo -
Tino Wildenhain