# uploadfile.py # this python script uploads a local file to Zope over http # thanx to VladDrac / www.amaze.nl for helping me out with # the authentication # todo: # - fix: hangs if userid/password is wrong # - check if file is uploaded succesfully # - use mimelib to encode the file (instead of using urlencode) import urllib # fill these in user='xxx' password='yyy' addfileurl='http://yourzopehost/some/dir/manage_addFile' useragent="uploadfile.py/0.1" filename='test.jpg' filetitle='a nice test picture' class MyUrlOpener(urllib.FancyURLopener): def prompt_user_passwd(self, host, realm): return (user,password) def __init__(self, *args): self.version = useragent urllib.FancyURLopener.__init__(self, *args) def main(): # use authentication and set the user agent urllib._urlopener = MyUrlOpener() # read the contents of filename into filebody f=open(filename) filebody=f.read() f.close # urlencode the id, title and file params = urllib.urlencode({'id': filename, 'title':filetitle, 'file':filebody}) # send the file to zope f=urllib.urlopen(addfileurl, params) if __name__ == '__main__': main()