[Plone-IT] Plone & mechanize (REPOST)

luigi scarso luigi.scarso a gmail.com
Mer 21 Gen 2009 17:24:09 UTC


(SCUSATE -- REPOST )
Salve,
mi trovo nella necessita' di fare numerosi e veloci upload automatici
di files secondo questo schema
1) crea una folder
2) upload di due files

Nella sue essenza il codice e' questo :


#####
from mechanize import Browser
import os
import random


def mkdir(br,path,name,desc):
    br.open("http://192.168.2.26:18080%(path)s/createObject?type_name=Folder"
%{'path' :path})
    br.select_form(name="edit_form")
    br['title'] = name
    br['description'] = desc
    response = br.submit()


def copy(br,path,src,dest):
    res = br.open("http://192.168.2.26:18080%(path)s/createObject?type_name=File"
%{'path' : path})
    res = br.select_form(name="edit_form")
    edit_form = [j for j in br.forms() if j.name == 'edit_form'][0]
    file_file = [j for j in edit_form.controls if j.name == 'file_file'][0]
    file_file.add_file(file_object=file(src,'rb'),filename=dest)
    response = br.submit()


if __name__ == '__main__':

    br   = Browser()
### autenticazione
    title = sys.argv[1]
    time.sleep(random.uniform(1,8))
    mkdir(br,path='/foo/Members/luigi',name=title,desc='')

    target_file = sys.argv[2]
    dest = os.path.basename(target_file)
    copy(br,path='/foo/Members/luigi/%s' %title,src=target_file,dest=dest)

    target_file = sys.argv[3]
    dest = os.path.basename(target_file)
    copy(br,path='/foo/Members/luigi/%s' %title,src=target_file,dest=dest)


Ma ho in media un 20% di errori del tipo :

Traceback (most recent call last):
  File "/opt/Plone-3.1.7/zeocluster/bin/zopepy", line 64, in ?
    execfile(sys.argv[0])
  File "upload-zopepy.py", line 44, in ?
    mkdir(br,path='/Lainox/Members/sergio',name=title,desc='')
  File "upload-zopepy.py", line 19, in mkdir
    br.open("http://192.168.2.26:18080%(path)s/createObject?type_name=Folder"
%{'path' :path})
  File
"/opt/Plone-3.1.7/zeocluster/parts/zope2/lib/python/mechanize/_mechanize.py",
line 177, in open
    return self._mech_open(url, data)
  File
"/opt/Plone-3.1.7/zeocluster/parts/zope2/lib/python/mechanize/_mechanize.py",
line 219, in _mech_open
    raise error
urllib2.HTTPError: HTTP Error 500: Internal Server Error


Ho provato a rallentare con
time.sleep(random.uniform(1,8))
ma niente .

Esiste un approccio alternativo ?

Grazie

-- 
luigi


-- 
luigi
-------------- parte successiva --------------
Un allegato HTML  stato rimosso...
URL: <http://lists.plone.org/pipermail/plone-plone-it/attachments/20090121/d6e88603/attachment.html>


Maggiori informazioni sulla lista Plone-IT