Closed trexfeathers closed 1 year ago
Thanks for the pyproj package, and thanks for any help you can provide 🙂
Side note: You need to set the environment variables before importing pyproj.
The logic is here if you would like to try to debug the issue on your environment.
Thanks @snowman2, I've updated the example to remove this ambiguity. As mentioned the problem also exists when the environment variable is set at the command line.
CORRECTION: after some confusion with IDE's and the PROJ_LIB
environment variable, this appears limited to specific types of environment we have on-premise. I will close this issue and re-open if I can give better replication instructions in future.
I am seeing this same problem on a machine that needs a specific CA bundle available to access remote resources.
I have set PROJ_CURL_CA_BUNDLE
and CURL_CA_BUNDLE
on my machine to point at the bundle, but I get the bug raised in #705 unless I specifically set the bundle using pyproj.network.set_ca_bundle_path("/path/to/ca-bundle.crt")
.
from pyproj.network import set_ca_bundle_path, set_network_enabled
from pyproj.transformer import Transformer
set_network_enabled(True)
set_ca_bundle_path()
t = Transformer.from_crs("epsg:27700", "epsg:4326")
print(t.transform(0, 0, None, errcheck=True))
Fails with:
Traceback (most recent call last):
File "/path/to/script.py", line 7, in <module>
print(t.transform(0, 0, None, errcheck=True))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/conda/env/lib/python3.11/site-packages/pyproj/transformer.py", line 820, in transform
return self._transformer._transform_point(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "pyproj/_transformer.pyx", line 813, in pyproj._transformer._Transformer._transform_point
pyproj.exceptions.ProjError: transform error: Network error when accessing a remote resource: (Internal Proj Error: Cannot open https://cdn.proj.org/uk_os_OSTN15_NTv2_OSGBtoETRS.tif: SSL certificate problem: unable to get local issuer certificate)
from pyproj.network import set_ca_bundle_path, set_network_enabled
from pyproj.transformer import Transformer
set_network_enabled(True)
set_ca_bundle_path("/path/to/ca-bundle.crt")
t = Transformer.from_crs("epsg:27700", "epsg:4326")
print(t.transform(0, 0, None, errcheck=True))
output:
(49.76680723514262, -7.55715980690519)
proj: 9.3.0 pyproj: 3.6.1 python: 3..11.6
It looks like the way in which the CA bundle path is initialised in pyproj bulldozes any environment variables pointing to that bundle (see https://github.com/OSGeo/PROJ/issues/3977). The easiest fix would be to remove this line you pointed to previously (@snowman2) as all it is doing is removing all possibility of finding a CA bundle.
Code Sample, a copy-pastable example if possible
Traceback when not using
set_ca_bundle_path()
:Problem description
Setting
PROJ_CURL_CA_BUNDLE
does not have the same effect asset_ca_bundle_path()
, indeed it doesn't seem to have any effect.Our specific security has made it necessary to use a local certificate file (located at
$SSL_CERT_PATH
in the example above) to allow scripts to access online resources. We can successfully point pyproj/PROJ at this certificate file usingpyproj.network.set_ca_bundle_path()
, but for global user config we would rather use thePROJ_CURL_CA_BUNDLE
environment variable described in the documentation (both pyproj and PROJ docs).Forcing
PROJ_NETWORK=OFF
does not seem like the correct solution, since the tools are ostensibly there to allow using a custom certificate.Expected Output
Setting the
PROJ_CURL_CA_BUNDLE
environment variable should enable Internet access via the referenced certificate file, in the same way thatset_ca_bundle_path()
does.Environment Information
pyproj -v
Installation method
mamba create -n pyproj_report pyproj
(Also seen in several other environments that contain pyproj).
Conda environment information (if you installed with conda):
Environment (
conda list
):Details about
conda
and system (conda info
):