upload without form as ExtDocument...how???
Dear all, I am trying to upload an extDocument which is located on my system without using the form but only using an external python script.(I am doing it because I have about 500 msworld files and i want to create a loop in test.py.(and I dont want to use Form)Please Help me! test.py:- def testext(self): f = open ("vin.doc","rb") dataread=f.read() fname='myvineet123' self.manage_addProduct['ExtDocument'].manage_addExtDocument(id=fname, title='t2', file=dataread) f.close() return dataread Above is my external python script.And I am calling the external method in the script below:- testpy.py:- for object in context.objectValues(['Folder']): if object.hasProperty('visible') and object.visible: context.testext(object) Now as I run testpy.py from zope i get the following error message:- Error Type: TypeError Error Value: open() argument 1 must be string without null bytes, not string Traceback (innermost last): File C:\zopewebs\lib\python\ZPublisher\Publish.py, line 223, in publish_module File C:\zopewebs\lib\python\ZPublisher\Publish.py, line 187, in publish File C:\zopewebs\lib\python\Zope\__init__.py, line 226, in zpublisher_exception_hook (Object: LockableItem) File C:\zopewebs\lib\python\ZPublisher\Publish.py, line 171, in publish File C:\zopewebs\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: testpy) File C:\zopewebs\lib\python\ZPublisher\Publish.py, line 112, in call_object (Object: testpy) File C:\zopewebs\lib\python\Shared\DC\Scripts\Bindings.py, line 324, in __call__ (Object: testpy) File C:\zopewebs\lib\python\Shared\DC\Scripts\Bindings.py, line 354, in _bindAndExec (Object: testpy) File C:\zopewebs\lib\python\Products\PythonScripts\PythonScript.py, line 363, in _exec (Object: testpy) (Info: ({'script': <PythonScript instance at 019A79D8>, 'context': <Folder instance at 019D6D00>, 'container': <Folder instance at 019D6D00>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 3, in testpy (Object: guarded_getattr) File C:\zopewebs\lib\python\Products\ExternalMethod\ExternalMethod.py, line 274, in __call__ (Object: testext) (Info: ((<Folder instance at 0122A5A8>,), {}, None)) File C:\zopewebs\Extensions\test.py, line 5, in testext (Object: LockableItem) File C:\zopewebs\lib\python\Products\ExtDocument\ExtDocument.py, line 41, in manage_addExtDocument (Object: LockableItem) File C:\zopewebs\lib\python\Products\ExtFile\ExtFile.py, line 371, in manage_file_upload (Object: CatalogAware) File C:\zopewebs\lib\python\Products\ExtFile\ExtFile.py, line 466, in _copy (Object: CatalogAware) TypeError: (see above) Can you kindly tell me where i am going wrong?? Best Regards, Vineet Ahuja
On Tuesday 09 October 2001 07:30 am, Vineet.Ahuja@de.abb.com wrote:
Dear all,
I am trying to upload an extDocument which is located on my system without using the form but only using an external python script.(I am doing it because I have about 500 msworld files and i want to create a loop in test.py.(and I dont want to use Form)Please Help me!
test.py:- def testext(self): f = open ("vin.doc","rb") dataread=f.read() fname='myvineet123' self.manage_addProduct['ExtDocument'].manage_addExtDocument(id=fname, title='t2', file=dataread) f.close() return dataread
Now as I run testpy.py from zope i get the following error message:- Error Type: TypeError Error Value: open() argument 1 must be string without null bytes, not string
try passing in the actual file object not the string read from the file kapil
First of all, I wouldn't use the name "self" for the parameter. Although it is not a Python reserved word, it is used by convention in class definitions, and it could be confusing later to call it that. I assume that you mean to eventually pass something related to a filename, right? Otherwise, why would you pass it the "object" parameter? Of course, you are not using the parameter for anything, so it doesn't matter what you send. The error message makes it looke like there is an invisible null character in the filename. Could you have typed the source on one system (like Linux) but are trying to run it on another (like Windows)? Try this. Edit the source on the same system as you are going to execute it on. If your editor has the option to change line terminations for different systems, set it for the system you are on. Change the code to read def testext(): filename='xxx.txt' f=open(filename) #... rest of file unchanged... This should make sure that you have a known legal string for the file name. It won't matter if you get an error message about not finding the file. Of course, this ***should*** make no difference, but you ***should not*** be getting that error so it is worth trying. Also, see if the code will run under just Python (without Zope). The results of this may give some guidance. Cheers, Tom P [<Vineet.Ahuja@de.abb.com>]
I am trying to upload an extDocument which is located on my system without using the form but only using an external python script.(I am doing it because I have about 500 msworld files and i want to create a loop in test.py.(and I dont want to use Form)Please Help me!
test.py:- def testext(self): f = open ("vin.doc","rb") dataread=f.read() fname='myvineet123' self.manage_addProduct['ExtDocument'].manage_addExtDocument(id=fname, title='t2', file=dataread) f.close() return dataread
Above is my external python script.And I am calling the external method in the script below:-
testpy.py:- for object in context.objectValues(['Folder']): if object.hasProperty('visible') and object.visible: context.testext(object)
Now as I run testpy.py from zope i get the following error message:- Error Type: TypeError Error Value: open() argument 1 must be string without null bytes, not string
participants (3)
-
kapil thangavelu -
Thomas B. Passin -
Vineet.Ahuja@de.abb.com