(SCUSATE -- REPOST )<br>Salve,<br>mi trovo nella necessita&#39; di fare numerosi e veloci upload automatici <br>di files secondo questo schema<br>1) crea una folder<br>2) upload di due files<br><br>Nella sue essenza il codice e&#39; questo :<br>
<br><br>#####<br>
from mechanize import Browser<br>import os<br>import random<br><br><br>def mkdir(br,path,name,desc):<br>&nbsp;&nbsp;&nbsp; br.open(&quot;http://192.168.2.26:18080%(path)s/createObject?type_name=Folder&quot; %{&#39;path&#39; :path})<br>
<div id=":15v" class="ArwC7c ckChnd">&nbsp;&nbsp;&nbsp; br.select_form(name=&quot;edit_form&quot;)<br>
&nbsp;&nbsp;&nbsp; br[&#39;title&#39;] = name<br>&nbsp;&nbsp;&nbsp; br[&#39;description&#39;] = desc<br>&nbsp;&nbsp;&nbsp; response = br.submit()<br><br><br>def copy(br,path,src,dest):<br>&nbsp;&nbsp;&nbsp; res = br.open(&quot;http://192.168.2.26:18080%(path)s/createObject?type_name=File&quot; %{&#39;path&#39; : path})<br>

&nbsp;&nbsp;&nbsp; res = br.select_form(name=&quot;edit_form&quot;)<br>&nbsp;&nbsp;&nbsp; edit_form = [j for j in br.forms() if <a href="http://j.name/" target="_blank">j.name</a> == &#39;edit_form&#39;][0]<br>&nbsp;&nbsp;&nbsp; file_file = [j for j in edit_form.controls if <a href="http://j.name/" target="_blank">j.name</a> == &#39;file_file&#39;][0]<br>

&nbsp;&nbsp;&nbsp; file_file.add_file(file_object=file(src,&#39;rb&#39;),filename=dest)<br>&nbsp;&nbsp;&nbsp; response = br.submit()<br><br><br>if __name__ == &#39;__main__&#39;:<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; br&nbsp;&nbsp; = Browser()<br>### autenticazione <br>&nbsp;&nbsp;&nbsp; title = sys.argv[1]<br>
&nbsp;&nbsp;&nbsp; time.sleep(random.uniform(1,8))<br>&nbsp;&nbsp;&nbsp; mkdir(br,path=&#39;/foo/Members/luigi&#39;,name=title,desc=&#39;&#39;)<br><br>&nbsp;&nbsp;&nbsp; target_file = sys.argv[2]<br>&nbsp;&nbsp;&nbsp; dest = os.path.basename(target_file)<br>&nbsp;&nbsp;&nbsp; copy(br,path=&#39;/foo/Members/luigi/%s&#39; %title,src=target_file,dest=dest)<br>
<br>&nbsp;&nbsp;&nbsp; target_file = sys.argv[3]<br>&nbsp;&nbsp;&nbsp; dest = os.path.basename(target_file)<br>&nbsp;&nbsp;&nbsp; copy(br,path=&#39;/foo/Members/luigi/%s&#39; %title,src=target_file,dest=dest)<br><br><br>Ma ho in media un 20% di errori del tipo :<br>
<br>Traceback (most recent call last):<br>&nbsp; File &quot;/opt/Plone-3.1.7/zeocluster/bin/zopepy&quot;, line 64, in ?<br>&nbsp;&nbsp;&nbsp; execfile(sys.argv[0])<br>&nbsp; File &quot;upload-zopepy.py&quot;, line 44, in ?<br>&nbsp;&nbsp;&nbsp; mkdir(br,path=&#39;/Lainox/Members/sergio&#39;,name=title,desc=&#39;&#39;)<br>
&nbsp; File &quot;upload-zopepy.py&quot;, line 19, in mkdir<br>&nbsp;&nbsp;&nbsp; br.open(&quot;http://192.168.2.26:18080%(path)s/createObject?type_name=Folder&quot; %{&#39;path&#39; :path})<br>&nbsp; File &quot;/opt/Plone-3.1.7/zeocluster/parts/zope2/lib/python/mechanize/_mechanize.py&quot;, line 177, in open<br>
&nbsp;&nbsp;&nbsp; return self._mech_open(url, data)<br>&nbsp; File &quot;/opt/Plone-3.1.7/zeocluster/parts/zope2/lib/python/mechanize/_mechanize.py&quot;, line 219, in _mech_open<br>&nbsp;&nbsp;&nbsp; raise error<br>urllib2.HTTPError: HTTP Error 500: Internal Server Error<br>
<br clear="all"><br>Ho provato a rallentare con<br>time.sleep(random.uniform(1,8))<br>ma niente .<br><br>Esiste un approccio alternativo ?<br><br>Grazie<br><br>-- <br><font color="#888888">luigi<br>
</font></div><br clear="all"><br>-- <br>luigi<br><br>