Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON schema files are not found on a mapped network drive under Windows 10 #207

Open
peterschaer opened this issue May 15, 2024 · 3 comments

Comments

@peterschaer
Copy link

In our environment (Windows 10), mappyfile is installed on a mapped network drive. In this case mappyfile cannot find its schema files (*.json) in the schemas subdirectory. The following error message is displayed:

>>> import mappyfile
>>> mapfile = mappyfile.open(r"C:\ProgramData\OEREBK\oerebpruef\oerebpruef\oerebpruef_gemeinde.map")
>>> mappyfile.dumps(mapfile)
Traceback (most recent call last):
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\urllib\request.py", line 1503, in open_local_file
    stats = os.stat(localfile)
FileNotFoundError: [WinError 3] Das System kann den angegebenen Pfad nicht finden: '\\a2za-cfs-data0.jgk.be.ch\\data0\\GIS02\\Anwend\\Tools\\Python_Module\\Python_Installation\\Python39\\site-packages\\mappyfile\\schemas\\onoff.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\jsonref.py", line 130, in callback
    base_doc = self.loader(uri)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\jsonref.py", line 255, in jsonloader
    with urlopen(uri) as content:
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\urllib\request.py", line 1481, in file_open
    return self.open_local_file(req)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\urllib\request.py", line 1520, in open_local_file
    raise URLError(exp)
urllib.error.URLError: <urlopen error [WinError 3] Das System kann den angegebenen Pfad nicht finden: '\\a2za-cfs-data0.jgk.be.ch\\data0\\GIS02\\Anwend\\Tools\\Python_Module\\Python_Installation\\Python39\\site-packages\\mappyfile\\schemas\\onoff.json'>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\mappyfile\utils.py", line 414, in dumps
    return _pprint(
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\mappyfile\utils.py", line 478, in _pprint
    return pp.pprint(d)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\mappyfile\pprint.py", line 330, in pprint
    lines += self._format(composite)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\mappyfile\pprint.py", line 565, in _format
    line = self.process_attribute(
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\mappyfile\pprint.py", line 455, in process_attribute
    value = self.format_value(attr, attr_props, value)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\mappyfile\pprint.py", line 379, in format_value
    if any(i in ["enum"] for i in attr_props):
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\proxytypes.py", line 189, in proxied
    args.insert(arg_pos, self.__subject__)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\proxytypes.py", line 163, in __getattribute__
    return _oga(self, attr)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\proxytypes.py", line 121, in wrapper
    return method(self, *args, **kwargs)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\proxytypes.py", line 243, in __subject__
    self.cache = super(LazyProxy, self).__subject__
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\proxytypes.py", line 121, in wrapper
    return method(self, *args, **kwargs)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\proxytypes.py", line 227, in __subject__
    return self.callback()
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\proxytypes.py", line 121, in wrapper
    return method(self, *args, **kwargs)
  File "K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\jsonref.py", line 132, in callback
    raise self._error(
jsonref.JsonRefError: Error while resolving `file:///a2za-cfs-data0.jgk.be.ch/data0/GIS02/Anwend/Tools/Python_Module/Python_Installation/Python39/site-packages/mappyfile/schemas/onoff.json`: URLError: <urlopen error [WinError 3] Das System kann den angegebenen Pfad nicht finden: '\\a2za-cfs-data0.jgk.be.ch\\data0\\GIS02\\Anwend\\Tools\\Python_Module\\Python_Installation\\Python39\\site-packages\\mappyfile\\schemas\\onoff.json'>

If mappyfile is installed on a local drive (e.g. C:), the schema files can be found.

As a workaround, I have removed the call to os.path.realpath() in line 71 in validator.py.

return os.path.join(os.path.dirname(os.path.realpath(__file__)), "schemas")

The schema files are then found.

Environment:
Python 3.9.16
mappyfile 1.0.1
jsonref 1.1.0
jsonschema 4.22.0

@geographika
Copy link
Owner

@peterschaer - thanks for reporting. Now mappyfile is Python3 only this can probably be rewritten to use a path from the package resources.
In your example above what do the two different calls return?

# current / broken
print(os.path.join(os.path.dirname(os.path.realpath(__file__)), "schemas"))
# patched / working
print(os.path.join(os.path.dirname(__file__), "schemas"))

@peterschaer
Copy link
Author

Here are my return values:

print(os.path.join(os.path.dirname(os.path.realpath(__file__)), "schemas"))
\\a2za-cfs-data0.jgk.be.ch\data0\GIS02\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\mappyfile\schemas
print(os.path.join(os.path.dirname(__file__), "schemas"))
K:\Anwend\Tools\Python_Module\Python_Installation\Python39\site-packages\mappyfile\schemas

@geographika
Copy link
Owner

Interesting. Looks like realpath was updated to get the real path behind Windows network drive mappings in https://bugs.python.org/issue36112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants