Python 为什么我的Cloud Run出现断管错误?
我在我的云计算运行中遇到了一个错误,在我的日志中,它说Python 为什么我的Cloud Run出现断管错误?,python,google-cloud-platform,sqlalchemy,google-cloud-sql,google-cloud-run,Python,Google Cloud Platform,Sqlalchemy,Google Cloud Sql,Google Cloud Run,我在我的云计算运行中遇到了一个错误,在我的日志中,它说管道断了错误,当我检查代码中哪一行出错时,它在我的db2.comit()上。我的云运行从6个月前开始一直运行良好,没有任何错误,但现在出现了这个错误 下面是日志中的详细信息 Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", l
管道断了
错误,当我检查代码中哪一行出错时,它在我的db2.comit()
上。我的云运行从6个月前开始一直运行良好,没有任何错误,但现在出现了这个错误
下面是日志中的详细信息
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 190, in __call__
await super().__call__(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc from None
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 78, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
raise exc from None
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
response = await func(request)
File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 188, in app
raw_response = await run_endpoint_function(
File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 135, in run_endpoint_function
return await dependant.call(**values)
File "/app/api/endpoints.py", line 48, in detect
db2.commit()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1042, in commit
self.transaction.commit()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 504, in commit
self._prepare_impl()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 483, in _prepare_impl
self.session.flush()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2523, in flush
self._flush(objects)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2664, in _flush
transaction.rollback(_capture_exception=True)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
compat.raise_(
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
raise exception
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2624, in _flush
flush_context.execute()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
rec.execute(self)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 586, in execute
persistence.save_obj(
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 205, in save_obj
for (
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 373, in _organize_states_for_save
for state, dict_, mapper, connection in _connections_for_states(
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1602, in _connections_for_states
connection = uowtransaction.transaction.connection(base_mapper)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 314, in connection
return self._connection_for_bind(bind, execution_options)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 421, in _connection_for_bind
conn = self._parent._connection_for_bind(bind, execution_options)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 433, in _connection_for_bind
conn = bind._contextual_connect()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2304, in _contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2338, in _wrap_pool_connect
return fn()
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 364, in connect
return _ConnectionFairy._checkout(self)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 809, in _checkout
result = pool._dialect.do_ping(fairy.connection)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 560, in do_ping
cursor.execute(self._dialect_specific_select_one)
File "/usr/local/lib/python3.8/site-packages/pg8000/core.py", line 340, in execute
self._c.execute_unnamed(self, "begin transaction")
File "/usr/local/lib/python3.8/site-packages/pg8000/core.py", line 1214, in execute_unnamed
self.handle_messages(cursor)
File "/usr/local/lib/python3.8/site-packages/pg8000/core.py", line 1377, in handle_messages
code, data_len = ci_unpack(self._read(5))
struct.error: unpack_from requires a buffer of at least 5 bytes for unpacking 5 bytes at offset 0 (actual buffer size is 0)
这是发生错误的代码行
except Exception as e: # noqa
log = orm.LogPredictStatus(customer_id=customer_id, status_code=500, car_attribute=car.dict(), price=None, source='TEST', created_at=time_zone_jakarta)
db2.add(log)
db2.commit()
raise HTTPException(
status_code=500,
detail=str(e),
)
从我所看到的关于代码的少量信息来看,我猜测
log
中的某些内容不符合元素的预期。尝试调试log
包含的内容。某个地方有一个空的缓冲区字段。感谢@ewong的响应,好的,它现在解决了,这是由我脚本上的插入方法引起的。