[ome-devel] ometiff download toubles

Will Moore will at lifesci.dundee.ac.uk
Thu Feb 24 23:39:50 GMT 2011


Sorry, should have replied to the lists too.....

On 24 Feb 2011, at 23:38, Will Moore wrote:

> Hi Chris,
>
>  Are you developing within the OmeroWeb framework, as described  
> http://trac.openmicroscopy.org.uk/ome/wiki/OmeroWeb
>
> Based on the simplified example on that page, you would do  
> something like
>
>
> from omeroweb.webgateway.views import getBlitzConnection
>
> def dataset(request, imageId):
>     conn = getBlitzConnection (request)     # get a connection to  
> OMERO using values in the http request
>     img = conn.getImage(imageId)         # get image by ID
>     data = img.exportOmeTiff()
>
> Docs for that method are here:
> http://hudson.openmicroscopy.org.uk/job/OMERO/javadoc/epydoc/ 
> omero.gateway._ImageWrapper-class.html#exportOmeTiff
>
> I don't have a complete example to hand just now (not on my work  
> laptop) but can find more details for you tomorrow.
>
>
>   Will.
>
>
>
> On 24 Feb 2011, at 18:59, Wood, Christopher wrote:
>
>> Josh,
>>
>> I used
>> client = omero.client(host)
>> session = client.createSession(user, pw)
>> gateway = session.createGateway()
>>
>> image = gateway.getImage(id)
>> exporter = session.createExporter()
>>
>> and it is working like I expect.
>>
>> I  am getting the username and password from the request object,  
>> e.g.,
>>
>> username = request.session.get('username', r.get('username', None))
>>
>> Is it necessary to do this, or is the user, password, host, and  
>> port already set by the request?
>>
>> Thanks
>> Chris
>>
>> On 2/24/11 9:33 AM, "Josh Moore" <josh at glencoesoftware.com> wrote:
>>
>> Hi Chris,
>>
>> the message "Cannot configure during output" comes from  
>> ExporterI.java:
>>
>>   http://git.openmicroscopy.org/?p=ome.git;a=blob;f=components/ 
>> blitz/src/ome/services/blitz/impl/ExporterI.java;#l230
>>
>> and implies that addImage() was called after generateTiff(), but  
>> that certainly doesn't look possible from your code snippet. This  
>> may be caused by the service wrapper from omero.gateway, but I'll  
>> let others speak to that. You might want to try either using the  
>> raw service (acquired from the session as opposed to the  
>> BlitzGateway), or use the facilities of the gateway, like the  
>> exportOmeTiff method:
>>
>>   http://git.openmicroscopy.org/?p=ome.git;a=blob;f=components/ 
>> tools/OmeroPy/src/omero/gateway/__init__.py#l5641
>>
>> Cheers,
>> ~Josh.
>>
>>
>> On Feb 24, 2011, at 4:14 PM, Wood, Christopher wrote:
>>
>>> Hi,
>>>
>>> I am trying to write a python script to be able to download an  
>>> OME-TIFF from omeroweb.  The code below will work, but it only  
>>> works once. On the second attempt I get the error below the code.  
>>> On the third attempt, it stops working at omero needs to be  
>>> restarted.
>>>
>>> I do this same sort of thing for original raw files and I don't  
>>> have a problem.
>>>
>>> OMERO Beta4.2.2-r8718-Beta4.2-b56
>>> python 2.4
>>>
>>> Here is the process:
>>> 1) restart omero and omeroweb
>>> 2) goto http://chi/websimr/getOMETIFF/3914/
>>> 3) file downloads as expected
>>> 4) try the same or different file again, I get the error below
>>> 5) try again and omero need to be restarted. (Insight stop  
>>> responding,  webclient stop responding, ....)
>>>
>>> Let me know if you need anything from the log files.
>>>
>>> Thanks,
>>> Chris
>>> ====================================================
>>> def getOMETIFF(request, iid):
>>>
>>>    if conn is None or not conn.isConnected():
>>>        return HttpResponseRedirect(reverse('websimr_login'))
>>>
>>>    iid = int(iid)
>>>    image = conn.getImage(iid)
>>>    name = image.getName()
>>>    name = name.replace('\\', '/')
>>>    name = os.path.basename(name)
>>>    name = os.path.splitext(name)[0] + '.ome.tif'
>>>
>>>    exporter = conn.createExporter()
>>>    exporter.addImage(iid)            <------------ this line  
>>> causes problems **********************
>>>    exporter.generateTiff()
>>>
>>>
>>>    tempdir = settings.FILE_UPLOAD_TEMP_DIR
>>>    v1 = iid
>>>    v2 = conn._sessionUuid
>>>    tempname = os.path.join(tempdir,('%i-%s.download' % (v1, v2)))
>>>    temp = tempname.replace('\\','/')
>>>
>>>    handle = open(temp, 'wb')
>>>    offset = 0
>>>
>>>    while 1==1:
>>>        rv = exporter.read(offset, 512*512)
>>>        if not rv:
>>>            break
>>>        offset += len(rv)
>>>        handle.write(rv)
>>>
>>>
>>>    handle.close()
>>>
>>>    ometiff = FileWrapper(file(temp))
>>>    response = HttpResponse(ometiff)
>>>
>>>    response['Content-Length'] = str(offset)
>>>    response['Content-Type'] = 'application/force-download'
>>>
>>>    response['Content-Disposition']='attachment;filename=' + name
>>>    return response
>>>
>>> ====================================================
>>> this is the debuggingout put from the web page
>>> ---
>>> Environment:
>>>
>>> Request Method: GET
>>> Request URL: http://chi/websimr/getOMETIFF/3914/
>>> Django Version: 1.1.1
>>> Python Version: 2.4.3
>>> Installed Applications:
>>> ['django.contrib.admin',
>>> 'django.contrib.markup',
>>> 'django.contrib.auth',
>>> 'django.contrib.contenttypes',
>>> 'django.contrib.sessions',
>>> 'django.contrib.sites',
>>> 'omeroweb.feedback',
>>> 'omeroweb.webadmin',
>>> 'omeroweb.webclient',
>>> 'omeroweb.webgateway',
>>> 'omeroweb.webtest',
>>> 'omeroweb.websimr',
>>> 'omeroweb.limsweb',
>>> 'omeroweb.webmobile']
>>> Installed Middleware:
>>> ('django.middleware.common.CommonMiddleware',
>>> 'django.contrib.sessions.middleware.SessionMiddleware',
>>> 'django.middleware.doc.XViewMiddleware')
>>>
>>>
>>> Traceback:
>>> File "/OMERO/omero_dist/lib/python/django/core/handlers/base.py"  
>>> in get_response
>>>  92.                 response = callback(request, *callback_args,  
>>> **callback_kwargs)
>>> File "/OMERO/omero_dist/lib/python/omeroweb/websimr/views.py" in  
>>> getOMETIFF
>>>  114.     exporter.addImage(iid)
>>> File "/OMERO/omero_dist/lib/python/omero/gateway/__init__.py" in  
>>> wrapped
>>>  2306.             return inner(*args, **kwargs)
>>> File "/OMERO/omero_dist/lib/python/omero/gateway/__init__.py" in  
>>> inner
>>>  2267.             return f(*args, **kwargs)
>>> File "/OMERO/omero_dist/lib/python/omero_api_Exporter_ice.py" in  
>>> addImage
>>>  81.             return _M_omero.api.Exporter._op_addImage.invoke 
>>> (self, ((id, ), _ctx))
>>>
>>> Exception Type: ApiUsageException at /websimr/getOMETIFF/3914/
>>> Exception Value: exception ::omero::ApiUsageException
>>> {
>>>    serverStackTrace =
>>>    serverExceptionClass =
>>>    message = Cannot configure during output
>>> }
>>>
>>
>>
>> _______________________________________________
>> ome-devel mailing list
>> ome-devel at lists.openmicroscopy.org.uk
>> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel
>



More information about the ome-devel mailing list