如果我把 openai 或 deepseek 的 api key 写到 GUI 客户端里,然后把这个 GUI 客户端软件打包成 exe 软件分发给好多用户,我的 key 不会被用户使用网络抓包软件探测到而泄露呢? 我是为了提高响应速度所以才会这么做的,否则我也知道可以把这部分功能放到我的服务器上面,然后再转接给客户端。 除此之外不知道还有没有别的方法?
补充:
实际情况是抓不到到,哈哈哈,不知道是什么原因。
我参照这里的方法
https://www.cnblogs.com/yoyoketang/p/16984669.html
还是没有抓到,只是报错
Traceback (most recent call last):
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_transports\default.py", line 72, in map_httpcore_exceptions
yield
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_transports\default.py", line 236, in handle_request
resp = self._pool.handle_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 216, in handle_request
raise exc from None
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpcore\_sync\connection_pool.py", line 196, in handle_request
response = connection.handle_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpcore\_sync\http_proxy.py", line 317, in handle_request
stream = stream.start_tls(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpcore\_sync\http11.py", line 383, in start_tls
return self._stream.start_tls(ssl_context, server_hostname, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpcore\_backends\sync.py", line 152, in start_tls
with map_exceptions(exc_map):
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 158, in __exit__
self.gen.throw(value)
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 973, in _request
response = self._client.send(
^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_client.py", line 926, in send
response = self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_client.py", line 954, in _send_handling_auth
response = self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_client.py", line 991, in _send_handling_redirects
response = self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_client.py", line 1027, in _send_single_request
response = transport.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_transports\default.py", line 235, in handle_request
with map_httpcore_exceptions():
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 158, in __exit__
self.gen.throw(value)
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\httpx\_transports\default.py", line 89, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "F:\FunctionThread\ExampleSentenceDict.py", line 35, in <module>
exampleSentenceDict = generateExampleSentenceDict(['Defer','boost'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\FunctionThread\ExampleSentenceDict.py", line 23, in generateExampleSentenceDict
response = client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_utils\_utils.py", line 274, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\resources\chat\completions.py", line 668, in create
return self._post(
^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1260, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 937, in request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 997, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1075, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 997, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1075, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "C:\Users\22815\AppData\Local\Programs\Python\Python312\Lib\site-packages\openai\_base_client.py", line 1007, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
将 OpenAI 或 DeepSeek 的 API 密钥写入 GUI 客户端并打包成 EXE 软件分发,确实存在被网络抓包软件嗅探到的风险。虽然在某些情况下抓包软件可能无法捕获到密钥,但这并不意味着它是安全的。以下是一些关于此问题的详细分析和建议:
您提到实际情况是抓不到密钥,可能的原因包括:
您提供的错误信息表明 SSL 证书验证失败。以下是一些解决此问题的建议:
import httpx
# 禁用 SSL 验证
client = httpx.Client(verify=False)
将 API 密钥放在客户端是有风险的,建议通过后端代理的方式来保护密钥安全。如果您决定在客户端使用密钥,务必采取额外的安全措施来降低泄露风险。同时,处理 SSL 证书错误时,确保抓包工具配置正确,以便能够捕获和分析流量。
如果您有其他问题或需要进一步的帮助,请随时询问!