Can anyone explain what is happening here. I am using Saxon to transform an xml file(source) using a stylesheet(style) the result is then written to Postgres. The contents of source are uploaded in Zope and passed to the external method as a string. When I run this external method: import psycopg, string, re, subprocess def scholarpack_xml_transform(source): f=open('/opt/scholarpack/ancillary/source.xml','w') f.write(source) f.close source= '/opt/scholarpack/ancillary/source.xml' style='/opt/scholarpack/ancillary/style.xml' source1=source.replace(''','`') source2=source1.replace('NLPGaddress','BS7666address') p=re.compile("\'") source3=p.sub( '`' , source2) r = subprocess.Popen(['/opt/scholarpack/ancillary/jre/bin/java','-jar','./saxon.jar',source3,style], stdout = subprocess.PIPE,cwd = '/opt/scholarpack/ancillary/') r.wait() transformed = r.stdout.read() transformed1=transformed.replace(',)',')') conn = psycopg.connect("dbname=scholarpack user=scholarpack") curs = conn.cursor() do=curs.execute(transformed1) do conn.commit() conn.close I get a programming error thrown from the conn.commit() line and the method fails. However when I run the following script externally to Zope after the Zope failure (so that source.xml exists) the DB write is successful. #!/opt/scholarpack/python/bin/python import psycopg, string, re, subprocess source='source.xml' style='style.xml' source1=source.replace(''','`') source2=source1.replace('NLPGaddress','BS7666address') p=re.compile("\'") source3=p.sub( '`' , source2) r = subprocess.Popen(['/opt/scholarpack/ancillary/jre/bin/java','-jar','./saxon.jar',source3,style], stdout = subprocess.PIPE,cwd = '/opt/scholarpack/ancillary/') r.wait() transformed = r.stdout.read() transformed1=transformed.replace(',)',')') conn = psycopg.connect("dbname=scholarpack user=scholarpack") curs = conn.cursor() do=curs.execute(transformed1) do conn.commit() conn.close Can anyone point me in the correct direction? regards garry
+-------[ garry saddington ]---------------------- | Can anyone explain what is happening here. I am using Saxon to transform | an xml file(source) using a stylesheet(style) the result is then written | to Postgres. The contents of source are uploaded in Zope and passed to | the external method as a string. When I run this external method: [snip] | Can anyone point me in the correct direction? Text encoding? Would probably be a lot easier if you told us the error message in full that you get. -- Andrew Milton akm@theinternet.com.au
On Thu, 2006-10-19 at 03:18 +1000, Andrew Milton wrote:
+-------[ garry saddington ]---------------------- | Can anyone explain what is happening here. I am using Saxon to transform | an xml file(source) using a stylesheet(style) the result is then written | to Postgres. The contents of source are uploaded in Zope and passed to | the external method as a string. When I run this external method:
[snip]
| Can anyone point me in the correct direction?
Text encoding? The same files are used both times. The error log is not very helpful here but I enclose it for completeness. regards garry
Log Undo Ownership Security Site Error Log Site Error Log at /error_log Exception traceback Time 2006/10/18 18:42:33.586 GMT+1 User Name (User Id) scholarpack (scholarpack) Request URL http://localhost/scholarpack/admin/interoperability/upload/addCTF Exception Type ProgrammingError Exception Value Traceback (innermost last): * Module ZPublisher.Publish, line 113, in publish * Module ZPublisher.mapply, line 88, in mapply * Module ZPublisher.Publish, line 40, in call_object * Module Shared.DC.Scripts.Bindings, line 311, in __call__ * Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec * Module Products.PythonScripts.PythonScript, line 323, in _exec * Module None, line 11, in addCTF <PythonScript at /scholarpack/admin/interoperability/upload/addCTF> Line 11 * Module OFS.DTMLMethod, line 144, in __call__ <DTMLMethod at /scholarpack/admin/interoperability/upload/result> URL: http://localhost/scholarpack/admin/interoperability/upload/result/manage_mai... Physical Path:/scholarpack/admin/interoperability/upload/result * Module DocumentTemplate.DT_String, line 476, in __call__ * Module Shared.DC.Scripts.Bindings, line 325, in __render_with_namespace__ * Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec * Module Products.PythonScripts.PythonScript, line 323, in _exec * Module None, line 2, in test_html <PythonScript at /scholarpack/admin/interoperability/upload/test_html> Line 2 * Module Products.ExternalMethod.ExternalMethod, line 225, in __call__ __traceback_info__: (('<?xml version="1.0" encoding="ISO-8859-1"?>\n<CTfile>\n<CTFpupilData >\n <Pupil>\n <UPN>U925540006009</UPN>\n <Surname>Abara</Surname>\n <Forename>Tonna</Forename>\n <DOB>1989-07-17</DOB>\n <Gender>F</Gender>\n <BasicDetails>\n <PreferredSurname>Abara</PreferredSurname>\n <PreferredForename>Tona</PreferredForename>\n <NCyearActual>12</NCyearActual>\n <Ethnicity>BAFR</Ethnicity>\n <EthnicitySource>O</EthnicitySource>\n <Languages>\n <Type>\n <LanguageQualifier>F</LanguageQualifier>\n <Language>ENG</Language>\n </Type>\n </Languages>\n <FSMeligible>false</FSMeligible>\n <MedicalFlag>false</MedicalFlag>\n <EnrolStatus>C</EnrolStatus>\n </BasicDetails>\n <Address>\n <AddressLines>\n <Line1>H61 Road 42</Line1>\n <Line2>Victoria Garden City</Line2>\n <Line3>Box 72675</Line3>\n <Line4>Victoria Island</Line4>\n <Line5>Lagos</Line5>\n <Country>Nigeria</Country>\n </AddressLines>\n </Address>\n <Contacts>\n <Contact>\n <Title>Mr & Mrs</Title>\n <Surname>Abara</Surname>\n <Relationship>FAM</Relationship>\n <Responsibility>true</Responsibility>\n <Address>\n <AddressAsPupil>true</AddressAsPupil>\n </Address>\n <Phones>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>014618466</PhoneNo>\n </Phone>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>0208 5750766</PhoneNo>\n </Phone>\n </Phones>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RelLnkParentNo>1</RelLnkParentNo>\n <StudentResident>true</StudentResident>\n <FamilyMailMarker>true</FamilyMailMarker>\n <Salutation>Mr & Mrs Abara</Salutation>\n </SuppInfo>\n </Contact>\n </Contacts>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RMMSAttendanceType>C</RMMSAttendanceType>\n <StudentDetails>\n <Religion>n/s</Religion>\n <LanguageAtHome>ENG</LanguageAtHome>\n </StudentDetails>\n </SuppInfo>\n </Pupil>\n <Pupil>\n <UPN>U92554000501A</UPN>\n <Surname>Abdullah</Surname>\n <Forename>Safaris</Forename>\n <DOB>1995-07-08</DOB>\n <Gender>M</Gender>\n <BasicDetails>\n <PreferredSurname>Abdullah</PreferredSurname>\n <PreferredForename>Safaris</PreferredForename>\n <NCyearActual>7</NCyearActual>\n <Ethnicity>MOTH</Ethnicity>\n <EthnicitySource>T</EthnicitySource>\n <Languages>\n <Type>\n <LanguageQualifier>F</LanguageQualifier>\n <Language>ENG</Language>\n </Type>\n </Languages>\n <FSMeligible>false</FSMeligible>\n <MedicalFlag>false</MedicalFlag>\n <EnrolStatus>C</EnrolStatus>\n </BasicDetails>\n <Address>\n <AddressLines>\n <Line1>43 St Margarets Avenue</Line1>\n <Line2> </Line2>\n <Line3> </Line3>\n <Line4>Skegness</Line4>\n <Line5>Lincolnshire</Line5>\n <Postcode>PE25 2LX</Postcode>\n <Country>England</Country>\n </AddressLines>\n </Address>\n <Contacts>\n <Contact>\n <Title>Mrs</Title>\n <Surname>Lilley</Surname>\n <Relationship>PAM</Relationship>\n <Responsibility>true</Responsibility>\n <Address>\n <AddressAsPupil>true</AddressAsPupil>\n </Address>\n <Phones>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>01754 760193</PhoneNo>\n </Phone>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>07783 538592</PhoneNo>\n </Phone>\n </Phones>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RelLnkParentNo>1</RelLnkParentNo>\n <StudentResident>true</StudentResident>\n <FamilyMailMarker>true</FamilyMailMarker>\n <Salutation>Mrs Lilley</Salutation>\n </SuppInfo>\n </Contact>\n </Contacts>\n <StageAssessments>\n <KeyStage>\n <Stage>KS3</Stage>\n <StageAssessment>\n <Locale>ENG</Locale>\n <Year>2006</Year>\n <KSsubject>ENG</KSsubject>\n <Method>47</Method>\n <Component>SUB</Component>\n <ResultStatus>I</ResultStatus>\n <ResultQualifier>NS</ResultQualifier>\n <Result>0</Result>\n </StageAssessment>\n </KeyStage>\n </StageAssessments>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RMMSAttendanceType>C</RMMSAttendanceType>\n <StudentDetails>\n <Religion>n/s</Religion>\n <LanguageAtHome>ENG</LanguageAtHome>\n </StudentDetails>\n </SuppInfo>\n </Pupil>\n</CTFpupilData>\n</CTfile>\n',), {}, None) * Module /opt/scholarpack/instances/scholarpack/Extensions/pyana.py, line 18, in scholarpack_xml_transform ProgrammingError: Display traceback as text REQUEST form submit ' Add ' id 'ctfxml' file '<?xml version="1.0" encoding="ISO-8859-1"?>\n<CTfile>\n<CTFpupilData >\n <Pupil>\n <UPN>U925540006009</UPN>\n <Surname>Abara</Surname>\n <Forename>Tonna</Forename>\n <DOB>1989-07-17</DOB>\n <Gender>F</Gender>\n <BasicDetails>\n <PreferredSurname>Abara</PreferredSurname>\n <PreferredForename>Tona</PreferredForename>\n <NCyearActual>12</NCyearActual>\n <Ethnicity>BAFR</Ethnicity>\n <EthnicitySource>O</EthnicitySource>\n <Languages>\n <Type>\n <LanguageQualifier>F</LanguageQualifier>\n <Language>ENG</Language>\n </Type>\n </Languages>\n <FSMeligible>false</FSMeligible>\n <MedicalFlag>false</MedicalFlag>\n <EnrolStatus>C</EnrolStatus>\n </BasicDetails>\n <Address>\n <AddressLines>\n <Line1>H61 Road 42</Line1>\n <Line2>Victoria Garden City</Line2>\n <Line3>Box 72675</Line3>\n <Line4>Victoria Island</Line4>\n <Line5>Lagos</Line5>\n <Country>Nigeria</Country>\n </AddressLines>\n </Address>\n <Contacts>\n <Contact>\n <Title>Mr & Mrs</Title>\n <Surname>Abara</Surname>\n <Relationship>FAM</Relationship>\n <Responsibility>true</Responsibility>\n <Address>\n <AddressAsPupil>true</AddressAsPupil>\n </Address>\n <Phones>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>014618466</PhoneNo>\n </Phone>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>0208 5750766</PhoneNo>\n </Phone>\n </Phones>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RelLnkParentNo>1</RelLnkParentNo>\n <StudentResident>true</StudentResident>\n <FamilyMailMarker>true</FamilyMailMarker>\n <Salutation>Mr & Mrs Abara</Salutation>\n </SuppInfo>\n </Contact>\n </Contacts>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RMMSAttendanceType>C</RMMSAttendanceType>\n <StudentDetails>\n <Religion>n/s</Religion>\n <LanguageAtHome>ENG</LanguageAtHome>\n </StudentDetails>\n </SuppInfo>\n </Pupil>\n <Pupil>\n <UPN>U92554000501A</UPN>\n <Surname>Abdullah</Surname>\n <Forename>Safaris</Forename>\n <DOB>1995-07-08</DOB>\n <Gender>M</Gender>\n <BasicDetails>\n <PreferredSurname>Abdullah</PreferredSurname>\n <PreferredForename>Safaris</PreferredForename>\n <NCyearActual>7</NCyearActual>\n <Ethnicity>MOTH</Ethnicity>\n <EthnicitySource>T</EthnicitySource>\n <Languages>\n <Type>\n <LanguageQualifier>F</LanguageQualifier>\n <Language>ENG</Language>\n </Type>\n </Languages>\n <FSMeligible>false</FSMeligible>\n <MedicalFlag>false</MedicalFlag>\n <EnrolStatus>C</EnrolStatus>\n </BasicDetails>\n <Address>\n <AddressLines>\n <Line1>43 St Margarets Avenue</Line1>\n <Line2> </Line2>\n <Line3> </Line3>\n <Line4>Skegness</Line4>\n <Line5>Lincolnshire</Line5>\n <Postcode>PE25 2LX</Postcode>\n <Country>England</Country>\n </AddressLines>\n </Address>\n <Contacts>\n <Contact>\n <Title>Mrs</Title>\n <Surname>Lilley</Surname>\n <Relationship>PAM</Relationship>\n <Responsibility>true</Responsibility>\n <Address>\n <AddressAsPupil>true</AddressAsPupil>\n </Address>\n <Phones>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>01754 760193</PhoneNo>\n </Phone>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>07783 538592</PhoneNo>\n </Phone>\n </Phones>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RelLnkParentNo>1</RelLnkParentNo>\n <StudentResident>true</StudentResident>\n <FamilyMailMarker>true</FamilyMailMarker>\n <Salutation>Mrs Lilley</Salutation>\n </SuppInfo>\n </Contact>\n </Contacts>\n <StageAssessments>\n <KeyStage>\n <Stage>KS3</Stage>\n <StageAssessment>\n <Locale>ENG</Locale>\n <Year>2006</Year>\n <KSsubject>ENG</KSsubject>\n <Method>47</Method>\n <Component>SUB</Component>\n <ResultStatus>I</ResultStatus>\n <ResultQualifier>NS</ResultQualifier>\n <Result>0</Result>\n </StageAssessment>\n </KeyStage>\n </StageAssessments>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RMMSAttendanceType>C</RMMSAttendanceType>\n <StudentDetails>\n <Religion>n/s</Religion>\n <LanguageAtHome>ENG</LanguageAtHome>\n </StudentDetails>\n </SuppInfo>\n </Pupil>\n</CTFpupilData>\n</CTfile>\n' cookies dtpref_rows '20' dtpref_cols '100%' tree-s 'eJzTyCkw5NLIKTDiClZ3hANXW3WuAmOuRKCECUjWFEk20CMQJGsGljUHyVogy3qVg2QtuRLBQA8AguIYaQ' lazy items SESSION <bound method SessionDataManager.getSessionData of <SessionDataManager at /session_data_manager>> other TraversalRequestNameStack [] AUTHENTICATED_USER scholarpack URL 'http://localhost/scholarpack/admin/interoperability/upload/addCTF' SERVER_URL 'http://localhost' AUTHENTICATION_PATH '' traverse_subpath [] file '<?xml version="1.0" encoding="ISO-8859-1"?>\n<CTfile>\n<CTFpupilData >\n <Pupil>\n <UPN>U925540006009</UPN>\n <Surname>Abara</Surname>\n <Forename>Tonna</Forename>\n <DOB>1989-07-17</DOB>\n <Gender>F</Gender>\n <BasicDetails>\n <PreferredSurname>Abara</PreferredSurname>\n <PreferredForename>Tona</PreferredForename>\n <NCyearActual>12</NCyearActual>\n <Ethnicity>BAFR</Ethnicity>\n <EthnicitySource>O</EthnicitySource>\n <Languages>\n <Type>\n <LanguageQualifier>F</LanguageQualifier>\n <Language>ENG</Language>\n </Type>\n </Languages>\n <FSMeligible>false</FSMeligible>\n <MedicalFlag>false</MedicalFlag>\n <EnrolStatus>C</EnrolStatus>\n </BasicDetails>\n <Address>\n <AddressLines>\n <Line1>H61 Road 42</Line1>\n <Line2>Victoria Garden City</Line2>\n <Line3>Box 72675</Line3>\n <Line4>Victoria Island</Line4>\n <Line5>Lagos</Line5>\n <Country>Nigeria</Country>\n </AddressLines>\n </Address>\n <Contacts>\n <Contact>\n <Title>Mr & Mrs</Title>\n <Surname>Abara</Surname>\n <Relationship>FAM</Relationship>\n <Responsibility>true</Responsibility>\n <Address>\n <AddressAsPupil>true</AddressAsPupil>\n </Address>\n <Phones>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>014618466</PhoneNo>\n </Phone>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>0208 5750766</PhoneNo>\n </Phone>\n </Phones>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RelLnkParentNo>1</RelLnkParentNo>\n <StudentResident>true</StudentResident>\n <FamilyMailMarker>true</FamilyMailMarker>\n <Salutation>Mr & Mrs Abara</Salutation>\n </SuppInfo>\n </Contact>\n </Contacts>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RMMSAttendanceType>C</RMMSAttendanceType>\n <StudentDetails>\n <Religion>n/s</Religion>\n <LanguageAtHome>ENG</LanguageAtHome>\n </StudentDetails>\n </SuppInfo>\n </Pupil>\n <Pupil>\n <UPN>U92554000501A</UPN>\n <Surname>Abdullah</Surname>\n <Forename>Safaris</Forename>\n <DOB>1995-07-08</DOB>\n <Gender>M</Gender>\n <BasicDetails>\n <PreferredSurname>Abdullah</PreferredSurname>\n <PreferredForename>Safaris</PreferredForename>\n <NCyearActual>7</NCyearActual>\n <Ethnicity>MOTH</Ethnicity>\n <EthnicitySource>T</EthnicitySource>\n <Languages>\n <Type>\n <LanguageQualifier>F</LanguageQualifier>\n <Language>ENG</Language>\n </Type>\n </Languages>\n <FSMeligible>false</FSMeligible>\n <MedicalFlag>false</MedicalFlag>\n <EnrolStatus>C</EnrolStatus>\n </BasicDetails>\n <Address>\n <AddressLines>\n <Line1>43 St Margarets Avenue</Line1>\n <Line2> </Line2>\n <Line3> </Line3>\n <Line4>Skegness</Line4>\n <Line5>Lincolnshire</Line5>\n <Postcode>PE25 2LX</Postcode>\n <Country>England</Country>\n </AddressLines>\n </Address>\n <Contacts>\n <Contact>\n <Title>Mrs</Title>\n <Surname>Lilley</Surname>\n <Relationship>PAM</Relationship>\n <Responsibility>true</Responsibility>\n <Address>\n <AddressAsPupil>true</AddressAsPupil>\n </Address>\n <Phones>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>01754 760193</PhoneNo>\n </Phone>\n <Phone>\n <PhoneType>H</PhoneType>\n <PhoneNo>07783 538592</PhoneNo>\n </Phone>\n </Phones>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RelLnkParentNo>1</RelLnkParentNo>\n <StudentResident>true</StudentResident>\n <FamilyMailMarker>true</FamilyMailMarker>\n <Salutation>Mrs Lilley</Salutation>\n </SuppInfo>\n </Contact>\n </Contacts>\n <StageAssessments>\n <KeyStage>\n <Stage>KS3</Stage>\n <StageAssessment>\n <Locale>ENG</Locale>\n <Year>2006</Year>\n <KSsubject>ENG</KSsubject>\n <Method>47</Method>\n <Component>SUB</Component>\n <ResultStatus>I</ResultStatus>\n <ResultQualifier>NS</ResultQualifier>\n <Result>0</Result>\n </StageAssessment>\n </KeyStage>\n </StageAssessments>\n <SuppInfo>\n <SuppID>RMMS</SuppID>\n <RMMSAttendanceType>C</RMMSAttendanceType>\n <StudentDetails>\n <Religion>n/s</Religion>\n <LanguageAtHome>ENG</LanguageAtHome>\n </StudentDetails>\n </SuppInfo>\n </Pupil>\n</CTFpupilData>\n</CTfile>\n' PUBLISHED <PythonScript at /scholarpack/admin/interoperability/upload/addCTF> ACTUAL_URL 'http://localhost/scholarpack/admin/interoperability/upload/addCTF' URL0 http://localhost/scholarpack/admin/interoperability/upload/addCTF URL1 http://localhost/scholarpack/admin/interoperability/upload URL2 http://localhost/scholarpack/admin/interoperability URL3 http://localhost/scholarpack/admin URL4 http://localhost/scholarpack URL5 http://localhost BASE0 http://localhost BASE1 http://localhost BASE2 http://localhost/scholarpack BASE3 http://localhost/scholarpack/admin BASE4 http://localhost/scholarpack/admin/interoperability BASE5 http://localhost/scholarpack/admin/interoperability/upload BASE6 http://localhost/scholarpack/admin/interoperability/upload/addCTF environ HTTP_COOKIE 'dtpref_cols="100%"; dtpref_rows="20"; tree-s="eJzTyCkw5NLIKTDiClZ3hANXW3WuAmOuRKCECUjWFEk20CMQJGsGljUHyVogy3qVg2QtuRLBQA8AguIYaQ"' SERVER_SOFTWARE 'Zope/(Zope 2.8.1-final, python 2.4.2, linux2) ZServer/1.1' SCRIPT_NAME '' REQUEST_METHOD 'POST' HTTP_KEEP_ALIVE '300' SERVER_PROTOCOL 'HTTP/1.1' channel.creation_time 1161193342 CONNECTION_TYPE 'keep-alive' HTTP_ACCEPT_CHARSET 'ISO-8859-1,utf-8;q=0.7,*;q=0.7' HTTP_USER_AGENT 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060921 Ubuntu/dapper-security Firefox/1.5.0.7' HTTP_REFERER 'http://localhost/scholarpack/admin/interoperability/upload' SERVER_NAME '0.0.0.0' REMOTE_ADDR '127.0.0.1' PATH_TRANSLATED '/scholarpack/admin/interoperability/upload/addCTF' SERVER_PORT '80' CONTENT_LENGTH '6219' HTTP_HOST 'localhost' HTTP_ACCEPT 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5' GATEWAY_INTERFACE 'CGI/1.1' HTTP_ACCEPT_LANGUAGE 'en-us,en;q=0.5' CONTENT_TYPE 'multipart/form-data; boundary=---------------------------157551476518702369471701174458' HTTP_ACCEPT_ENCODING 'gzip,deflate' PATH_INFO '/scholarpack/admin/interoperability/upload/addCTF'
+-------[ garry saddington ]---------------------- | On Thu, 2006-10-19 at 03:18 +1000, Andrew Milton wrote: | > +-------[ garry saddington ]---------------------- | > | Can anyone explain what is happening here. I am using Saxon to transform | > | an xml file(source) using a stylesheet(style) the result is then written | > | to Postgres. The contents of source are uploaded in Zope and passed to | > | the external method as a string. When I run this external method: | > | > [snip] | > | > | Can anyone point me in the correct direction? | > | > Text encoding? | The same files are used both times. The error log is not very helpful | here but I enclose it for completeness. | regards | garry I'd add some debugging into the pyana.py file, at the point where it's raising the exception. -- Andrew Milton akm@theinternet.com.au
On Wed, Oct 18, 2006 at 06:13:38PM +0100, garry saddington wrote:
Can anyone explain what is happening here. I am using Saxon to transform an xml file(source) using a stylesheet(style) the result is then written to Postgres. The contents of source are uploaded in Zope and passed to the external method as a string. When I run this external method:
import psycopg, string, re, subprocess def scholarpack_xml_transform(source): f=open('/opt/scholarpack/ancillary/source.xml','w') f.write(source)
I have no idea what's causing your problem, but this raises red flags for me: if two people upload sources at the same time, you'll have problems here. If you really really must read/write files on the filesystem, either use locks or use python's tempfile module.
f.close source= '/opt/scholarpack/ancillary/source.xml' style='/opt/scholarpack/ancillary/style.xml' source1=source.replace(''','`') source2=source1.replace('NLPGaddress','BS7666address') p=re.compile("\'") source3=p.sub( '`' , source2) r = subprocess.Popen(['/opt/scholarpack/ancillary/jre/bin/java','-jar','./saxon.jar',source3,style], stdout = subprocess.PIPE,cwd = '/opt/scholarpack/ancillary/')
Are you just using saxon for xslt processing? If so, IMO using an external process for that is severe overkill. Get lxml and try something like this: from lxml import etree style = etree.XSLT(etree.parse(some_file_object)) transformed = style.apply(source_data) but again, this doesn't address your immediate problem :) -- Paul Winkler http://www.slinkp.com
On Wed, 2006-10-18 at 15:07 -0400, Paul Winkler wrote:
On Wed, Oct 18, 2006 at 06:13:38PM +0100, garry saddington wrote:
Can anyone explain what is happening here. I am using Saxon to transform an xml file(source) using a stylesheet(style) the result is then written to Postgres. The contents of source are uploaded in Zope and passed to the external method as a string. When I run this external method:
import psycopg, string, re, subprocess def scholarpack_xml_transform(source): f=open('/opt/scholarpack/ancillary/source.xml','w') f.write(source)
I have no idea what's causing your problem, but this raises red flags for me: if two people upload sources at the same time, you'll have problems here. There is no chance of this as it is a one-off populate the db exercise.
If you really really must read/write files on the filesystem, either use locks or use python's tempfile module.
f.close source= '/opt/scholarpack/ancillary/source.xml' style='/opt/scholarpack/ancillary/style.xml' source1=source.replace(''','`') source2=source1.replace('NLPGaddress','BS7666address') p=re.compile("\'") source3=p.sub( '`' , source2) r = subprocess.Popen(['/opt/scholarpack/ancillary/jre/bin/java','-jar','./saxon.jar',source3,style], stdout = subprocess.PIPE,cwd = '/opt/scholarpack/ancillary/')
Are you just using saxon for xslt processing? If so, IMO using an external process for that is severe overkill. Get lxml and try something like this:
from lxml import etree style = etree.XSLT(etree.parse(some_file_object)) transformed = style.apply(source_data) Thank you I've never heard of this, I'll give it a try. I was using 4suite but it started to misbehave in the way that I wanted to use it. regards Garry
but again, this doesn't address your immediate problem :)
garry saddington wrote at 2006-10-18 18:13 +0100:
... import psycopg, string, re, subprocess def scholarpack_xml_transform(source): f=open('/opt/scholarpack/ancillary/source.xml','w') f.write(source) f.close
The line above looks buggy: missing "()".
... do=curs.execute(transformed1) do
The line above looks doubtfull: no effect
conn.commit() conn.close
I get a programming error thrown from the conn.commit() line and the method fails.
Almost surely, "postgres" does not like the command your have generated. It is quite picky with binary data... -- Dieter
participants (4)
-
Andrew Milton -
Dieter Maurer -
garry saddington -
Paul Winkler