[Zope] upload without form as ExtDocument...how???

Thomas B. Passin tpassin@mitretek.org
Tue, 9 Oct 2001 11:04:17 -0400

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():
   #... 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.


Tom P

> 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