I am working on calling the Rest-API from Python. All the Rest-API I have tested using Postman and are working fine. But, While executing those using Python scripts I am facing certification error.
I am executing the python script from windows cmd.
Below is the code:
import requests
import certifi
from urllib.request import urlopen
import ssl
requestCert = 'https://someurl.com:4443/api/11/projects/'
urlopen(requestCert, context=ssl.create_default_context(cafile=certifi.where()))
headers = {
"Authorization": "fdsfsfdewrwerwer",
"X-Auth-Token": "YxzcfhnkniGVGljghjmwCIGLfhfsfdzxc4o5sSADtaT2"
}
#response = requests.get('https://someurl.com:4443/api/11/projects', headers=headers)
#response = requests.get('https://someurl.com:4443/api/11/projects', headers=headers, verify=certifi.where())
response = requests.get('https://someurl.com:4443/api/11/projects', headers=headers, verify='server.pem')
print(response)
Further debugging. . .
even simple import requests print('Hello, world!')
and pip install requests
giving same error. I guess the issue is not in the code, it's something with the module import functionality.
The error that I am getting is as below.
Traceback (most recent call last):
File "C:\Users\eddie\Desktop\PyPoc\Py_Job\importJob.py", line 1, in <module>
import requests
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\__init__.py", line 147, in <module>
from . import packages, utils
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\utils.py", line 24, in <module>
from . import certs
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\certs.py", line 14, in <module>
from certifi import where
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\wrapt\importer.py", line 177, in _exec_module
notify_module_loaded(module)
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\wrapt\wrappers.py", line 578, in __call__
return self._self_wrapper(self.__wrapped__, self._self_instance,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\wrapt\decorators.py", line 470, in _synchronized
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\wrapt\importer.py", line 136, in notify_module_loaded
hook(module)
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\certifi_win32\wrapt_certifi.py", line 20, in apply_patches
certifi_win32.wincerts.CERTIFI_PEM = certifi.where()
^^^^^^^^^^^^^^^
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\site-packages\certifi\core.py", line 37, in where
_CACERT_PATH = str(_CACERT_CTX.__enter__())
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\importlib\resources\_common.py", line 80, in _tempfile
os.write(fd, reader())
^^^^^^^^
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\importlib\resources\abc.py", line 76, in read_bytes
with self.open('rb') as strm:
^^^^^^^^^^^^^^^
File "C:\Users\eddie\AppData\Local\Programs\Python\Python311\Lib\importlib\resources\_adapters.py", line 141, in open
raise FileNotFoundError("Can't open orphan path")
FileNotFoundError: Can't open orphan path
Can you please let me what changes I need to do ?