gpt4 book ai didi

python - 客户端向 HTTPS 服务器发送 HTTP 请求

转载 作者:行者123 更新时间:2023-12-02 12:12:39 27 4
gpt4 key购买 nike

我有一个在虚拟机上运行的 python 应用程序,这是一个遗留问题,现在我正在迁移到 Kubernetes。
我用 influxdb==5.2.3包,连​​接到这种形式 Influx(host=r'influx_HOST', port=8086, username='MY_USER', password='***', database='DB_NAME', ssl=True) .这个python脚本使用SSL证书调用InfluxBD,当我直接使用python app.py运行时效果很好,但是,问题在于:
我 dockerized 脚本显示了以下错误。

Traceback (most recent call last):
File "app.py", line 591, in <module>
get_horas_stock()
File "app.py", line 513, in get_horas_stock
df_temp = influx_temperatura.multiple_query_to_df(queries_temperatura)
File "/usr/src/app/analitica_py_lib_conexiones/conexion_influx.py", line 82, in multiple_query_to_df
resultado = self.__cliente.query(";".join(queries))
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 445, in query
response = self.request(
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 302, in request
raise InfluxDBClientError(response.content, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: Client sent an HTTP request to an HTTPS server.
我了解到,从容器内部,脚本使用 https 调用 Influx,但我认为连接使用 Http 重定向到容器外部并丢失了所有 SSL 配置,为什么?我不知道。
我测试部署在 Kubernetes 上
我试图在 Kubernetes 上部署,认为我遇到了同样的错误,但它已经改变了。
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 360, in _error_catcher
yield
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 442, in read
data = self._fp.read(amt)
File "/usr/local/lib/python3.8/http/client.py", line 454, in read
n = self.readinto(b)
File "/usr/local/lib/python3.8/http/client.py", line 498, in readinto
n = self.fp.readinto(b)
File "/usr/local/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 750, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 494, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 459, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.8/site-packages/urllib3/response.py", line 378, in _error_catcher
raise ProtocolError('Connection broken: %r' % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "app.py", line 591, in <module>
get_horas_stock()
File "app.py", line 513, in get_horas_stock
df_temp = influx_temperatura.multiple_query_to_df(queries_temperatura)
File "/usr/src/app/analitica_py_lib_conexiones/conexion_influx.py", line 82, in multiple_query_to_df
resultado = self.__cliente.query(";".join(queries))
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 445, in query
response = self.request(
File "/usr/local/lib/python3.8/site-packages/influxdb/client.py", line 274, in request
response = self._session.request(
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 686, in send
r.content
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 828, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 753, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))
不知道是否与之前的错误有关。
enter image description here
已编辑
文件
FROM python:3.8.2-buster

WORKDIR /usr/src/app

COPY . .

RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 8080

CMD ["python", "app.py"]
Kubernetes 部署 YML
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-ms
spec:
replicas: 1
selector:
matchLabels:
ip-service: my-ms
template:
metadata:
labels:
ip-service: my-ms
spec:
containers:
- name: my-ms
image: myprivate.azurecr.io/my-ms:latest
ports:
- containerPort: 8080
resources:
requests:
cpu: 100m
memory: 10Mi
imagePullSecrets:
- name: tecnoregistry
编辑 2
我在 Kubernetes 上遇到了同样的错误,但是在本地运行脚本时,我在服务调用中将 SSL 值从 True 更改为 False Influx(host=r'influx_HOST', port=8086, username='MY_USER', password='***', database='DB_NAME', ssl=False) .
~$ python3 app.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 360, in _error_catcher
yield
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 442, in read
data = self._fp.read(amt)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 457, in read
n = self.readinto(b)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 501, in readinto
n = self.fp.readinto(b)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 750, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 494, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 459, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/response.py", line 378, in _error_catcher
raise ProtocolError('Connection broken: %r' % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(54, 'Connection reset by peer')", ConnectionResetError(54, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "app.py", line 1272, in <module>
generate_excels_consumo()
File "/Volumes/DATA/IdeaProjects/australia/analitica_py_sw_recolect_info/calculo_excels.py", line 206, in generate_excels_consumo
df_sector = influx_kpis.multiple_query_to_multiple_df(queries)
File "/Volumes/DATA/IdeaProjects/australia/analitica_py_sw_recolect_info/analitica_py_lib_conexiones/conexion_influx.py", line 126, in multiple_query_to_multiple_df
resultado = self.__cliente.query(";".join(query))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/influxdb/client.py", line 450, in query
expected_response_code=expected_response_code
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/influxdb/client.py", line 283, in request
timeout=self._timeout
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/sessions.py", line 686, in send
r.content
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 828, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 753, in generate
raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(54, 'Connection reset by peer')", ConnectionResetError(54, 'Connection reset by peer'))

最佳答案

好像是网络问题。由于代理,我在连接 MongoDB 时遇到了微笑问题。凡事都有可能出现这个问题。

默认情况下,Docker 运行的每个容器都有自己的网络命名空间。

提供一些解决方法:

  • traceroute <cluster-ip>执行此命令并检查是否到达容器附加容器内部的集群并执行命令docker exec -it container /bin/bash .
  • 检查代理。 export检查与代理相关的环境变量。
  • curl www.google.com
  • 尝试连接集群中的其他东西。例如MySQL等(有一次机器自动给我写黑名单我试图解决连接问题2天)
  • 尝试使用 python-slim 图像。纤薄的图像基于 ubuntu。

  • 是很好的理解和解决docker连接问题的文档。

    https://pythonspeed.com/articles/docker-connection-refused/

    关于python - 客户端向 HTTPS 服务器发送 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61017106/

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