pythonpython-3.xdeepzoom

Unable to open URL thats local file path


I downloaded the latest version of Python (3.8) on my windows 10 laptop and wanted to run the deepzoom.py program available here . I am struggling to fix this simple path issue on my python program. (I am reasonably new to Python) and am hoping its something obvious.

import os
import deepzoom

SOURCE=r'c:\work\dzimages\helloworld.jpg'
DESTINATION=r'c:\work\dzimages\output\helloworld.dzi'


creator = deepzoom.ImageCreator(
    tile_size=128,
    tile_overlap=2,
    tile_format="png",
    image_quality=0.8,
    resize_filter="bicubic",
)

# Create Deep Zoom image pyramid from source
creator.create(SOURCE,DESTINATION)

I am getting a path not found on the SOURCE. Ideally source should be a http(s) URL, but i assume it would work on a local file url. I have tried various combinations of double slash and file:// and a lot of other things as suggested on the web and none seemed to work. So there is something obvious that i am missing. Thanks! This is my full error

Traceback (most recent call last):
  File "C:\Work\TestProjects\deepzoom.py-master\deepzoom.py-master\examples\helloworld\helloworld-dzi.py", line 25, in <module>
  creator.create(SOURCE,DESTINATION)
  File "C:\Work\Python\lib\site-packages\deepzoomtools-2.0.0a2-py3.8.egg\deepzoom\__init__.py", line 493, in f_retry
  File "C:\Work\Python\lib\site-packages\deepzoomtools-2.0.0a2-py3.8.egg\deepzoom\__init__.py", line 536, in safe_open
  File "C:\Work\Python\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Work\Python\lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "C:\Work\Python\lib\urllib\request.py", line 547, in _open
    return self._call_chain(self.handle_open, 'unknown',
  File "C:\Work\Python\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "C:\Work\Python\lib\urllib\request.py", line 1390, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: c>

Solution

  • deepzoom is seeing the c: at the beginning of your string as a URI scheme. You could remove that, or providing a full URI like this might work:

    SOURCE='file:///c:/work/dzimages/helloworld.jpg'
    

    See https://en.wikipedia.org/wiki/File_URI_scheme for more information.