gpt4 book ai didi

python - 来自 urllib3 HTTPSConnectionPool request_encode_body 证书问题

转载 作者:太空宇宙 更新时间:2023-11-03 14:07:55 35 4
gpt4 key购买 nike

我试图在 https url 上发送请求以获取数据,当我尝试在浏览器上执行时,域需要安全证书。

但我的问题是如何在我的 python 代码上调用 url 来获取响应数据?我写了以下代码:

conn = HTTPSConnectionPool(BETTING_CONFG['api_url'],
maxsize = BETTING_CONFG['connection_max_size'])

response = conn.request_encode_body('POST', service_uri, headers= headers,
encode_multipart=False, body = body)

我得到以下响应:

Response: status = 200, payload = {"_status":"error","payload":{"_code":"0-2","_message":"invalid_app_key"}} .

和终端上的这个警告:

/usr/local/lib/python2.7/dist-packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:821: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
[555WIN] 2016-05-30 14:02:06,043 - INFO - Betting Response: status = 200, payload = {"_status":"error","payload":{"_code":"0-2","_message":"invalid_app_key"}} .
Traceback (most recent call last):
File "/usr/lib/python2.7/logging/handlers.py", line 76, in emit
if self.shouldRollover(record):
File "/usr/lib/python2.7/logging/handlers.py", line 156, in shouldRollover
msg = "%s\n" % self.format(record)
File "/usr/lib/python2.7/logging/__init__.py", line 724, in format
return fmt.format(record)
File "/usr/lib/python2.7/logging/__init__.py", line 464, in format
record.message = record.getMessage()
File "/usr/lib/python2.7/logging/__init__.py", line 324, in getMessage
msg = str(self.msg)
TypeError: __str__ returned non-string (type dict)
Logged from file jsonapi.py, line 137
Traceback (most recent call last):
File "/usr/lib/python2.7/logging/__init__.py", line 851, in emit
msg = self.format(record)
File "/usr/lib/python2.7/logging/__init__.py", line 724, in format
return fmt.format(record)
File "/usr/lib/python2.7/logging/__init__.py", line 464, in format
record.message = record.getMessage()
File "/usr/lib/python2.7/logging/__init__.py", line 324, in getMessage
msg = str(self.msg)
TypeError: __str__ returned non-string (type dict)

当我在 chrome 上添加证书并尝试在 postman 上发送请求时,它工作正常吗?

有什么解决办法吗?

最佳答案

请理解您的 Chrome 证书存储区与您的 Python 应用程序使用的证书存储区不同。

如果您只能获得有效的 SSL 证书而不是尝试使自签名证书起作用,那将会容易得多。

此外,请务必升级您的 Python 和 urllib。这些警告信息不容忽视!先解决它们!

SSL 证书过去很贵,但现在您可以从 LetsEncrypt 获得有效、完全支持的免费证书。 .我运行我的 own website使用他们的证书,我可以向您保证,Python 加载他们的证书没有问题。

关于python - 来自 urllib3 HTTPSConnectionPool request_encode_body 证书问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37527810/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com