Python 带有SSL证书的Django请求

Python 带有SSL证书的Django请求,python,python-requests,pyopenssl,Python,Python Requests,Pyopenssl,在django视图中,我需要向另一个API发出post请求。 API要求将SSL证书附加到请求。我有ssl.crt文件 我如何实现这一点 我尝试在此处使用此实现: 但即使我以管理员身份运行pycharm,也会出现此错误: Traceback (most recent call last): File "C:\Applications\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner

在django视图中,我需要向另一个API发出post请求。 API要求将SSL证书附加到请求。我有ssl.crt文件

我如何实现这一点

我尝试在此处使用此实现:

但即使我以管理员身份运行pycharm,也会出现此错误:

Traceback (most recent call last):
  File "C:\Applications\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Applications\venv\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Applications\venv\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "", line 350, in pge_auth_v1_redirect_view
    with pfx_to_pem(pem_file_path, '') as cert:
  File "c:\program files\python37\Lib\contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "", line 271, in pfx_to_pem
    f_pem = open(t_pem.name, 'wb')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\fpier\\AppData\\Local\\Temp\\tmpg7i7qtun.pem'

我找到的解决方案是通过合并公共和私有文件来创建pem文件

        req = requests.post(
            url,
            params=params,
            headers=headers,
            auth=client_auth,
            verify=True,
            cert=self._pem_file_path
        )