i'm unsuccessfully trying to connect my python project to a postgres DB using Prisma
I'm following this https://prisma-client-py.readthedocs.io/en/stable/
# schema.prisma
generator db {
provider = "prisma-client-py"
interface = "asyncio"
}
datasource db {
provider = "postgresql"
url = "postgresql://imb123:pass3876#localhost:5432/ibm123?schema=public"
}
model Post {
id String #id #default(cuid())
created_at DateTime #default(now())
updated_at DateTime #updatedAt
title String
published Boolean
desc String?
}
main.py
import asyncio
from prisma import Prisma
async def main() -> None:
db = Prisma()
await db.connect()
post = await db.post.create(
{
'title': 'Hello from prisma!',
'desc': 'Prisma is a database toolkit and makes databases easy.',
'published': True,
}
)
print(f'created post: {post.json(indent=2, sort_keys=True)}')
found = await db.post.find_unique(where={'id': post.id})
assert found is not None
print(f'found post: {found.json(indent=2, sort_keys=True)}')
await db.disconnect()
if __name__ == '__main__':
asyncio.run(main())
db push and prisma generate finished successfully meaning the connect from CLI is ok.
table_catalog | table_schema | table_name | table_type | self_referencing_column_name | reference_generation | user_defined_type_catalog | user_defined_type_schema | user_defined_type_name | is_insertable_into | is_typed | commit_action
---------------+--------------------+---------------------------------------+------------+------------------------------+----------------------+---------------------------+--------------------------+------------------------+--------------------+----------+---------------
ibm123 | public | Post | BASE TABLE | | | | | | YES | NO |
The error raised from await db.connect()
/Users/ibm123/PycharmProjects/pythonProject/venv/bin/python /Users/ibm123/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 164, in try_connect
stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 1691, in connect_tcp
await get_running_loop().create_connection(
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1065, in create_connection
raise exceptions[0]
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1050, in create_connection
sock = await self._connect_sock(
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 961, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 500, in sock_connect
return await fut
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/selector_events.py", line 535, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 61] Connect call failed ('::1', 59712, 0, 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/_exceptions.py", line 8, in map_exceptions
yield
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/anyio/_core/_sockets.py", line 222, in connect_tcp
raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/_async/connection.py", line 86, in handle_async_request
raise exc
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/_async/connection.py", line 63, in handle_async_request
stream = await self._connect(request)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/_async/connection.py", line 111, in _connect
stream = await self._network_backend.connect_tcp(**kwargs)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/backends/auto.py", line 29, in connect_tcp
return await self._backend.connect_tcp(
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/backends/asyncio.py", line 109, in connect_tcp
stream: anyio.abc.ByteStream = await anyio.connect_tcp(
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
raise to_exc(exc)
httpcore.ConnectError: All connection attempts failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/prisma/engine/query.py", line 161, in spawn
data = await self.request('GET', '/status')
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/prisma/engine/http.py", line 96, in request
resp = await self.session.request(method, url, **kwargs)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/prisma/_async_http.py", line 28, in request
return Response(await self.session.request(method, url, **kwargs))
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_client.py", line 1527, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_client.py", line 1614, in send
response = await self._send_handling_auth(
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_client.py", line 1642, in _send_handling_auth
response = await self._send_handling_redirects(
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_client.py", line 1679, in _send_handling_redirects
response = await self._send_single_request(request)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_client.py", line 1716, in _send_single_request
response = await transport.handle_async_request(request)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: All connection attempts failed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/ibm123/PycharmProjects/pythonProject/main.py", line 25, in <module>
asyncio.run(main())
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/Cellar/python#3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "/Users/ibm123/PycharmProjects/pythonProject/main.py", line 6, in main
await db.connect()
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/prisma/client.py", line 238, in connect
await self.__engine.connect(
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/prisma/engine/query.py", line 109, in connect
await self.spawn(file, timeout=timeout, datasources=datasources)
File "/Users/ibm123/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/prisma/engine/query.py", line 180, in spawn
raise errors.EngineConnectionError(
prisma.engine.errors.EngineConnectionError: Could not connect to the query engine
Related
I got errors when I run pulumi up.
Error:
pulumi_docker.docker.ResourceError: No digest available for image 1234567890987.dkr.ecr.us-west-2.amazonaws.com/cloud/abcd-svc-4c4ac5e
pulumi up
versions:
pulumi==3.40.1
pulumi-aws==5.15.0
pulumi-docker==3.4.1
python-dotenv==0.21.0
Type Name Plan Info
pulumi:pulumi:Stack abcdef-staging-1234567890987 1 error; 1 message
├─ docker:image:Image cloud/abcd-svc
└─ aws:ssm:Parameter ABCD_APP_MYSQL_DB_HOST create
Diagnostics:
pulumi:pulumi:Stack (abcdef-staging-1234567890987):
error: Program failed with an unhandled exception:
Traceback (most recent call last):
File "/home/ubuntu/.pulumi/bin/pulumi-language-python-exec", line 179, in <module>
loop.run_until_complete(coro)
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 126, in run_in_stack
await run_pulumi_func(lambda: Stack(func))
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 51, in run_pulumi_func
await wait_for_rpcs()
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/stack.py", line 73, in wait_for_rpcs
await RPC_MANAGER.rpcs.pop()
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc_manager.py", line 68, in rpc_wrapper
result = await rpc
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 99, in is_value_known
return await is_known and not contains_unknowns(await future)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 99, in is_value_known
return await is_known and not contains_unknowns(await future)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 99, in is_value_known
return await is_known and not contains_unknowns(await future)
[Previous line repeated 25 more times]
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/resource.py", line 514, in do_register
resolver = await prepare_resource(res, ty, custom, remote, props, opts, typ)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/resource.py", line 124, in prepare_resource
serialized_props = await rpc.serialize_properties(
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc.py", line 207, in serialize_properties
result = await serialize_property(
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc.py", line 375, in serialize_property
is_known = await output._is_known
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc_manager.py", line 68, in rpc_wrapper
result = await rpc
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 99, in is_value_known
return await is_known and not contains_unknowns(await future)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 99, in is_value_known
return await is_known and not contains_unknowns(await future)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 99, in is_value_known
return await is_known and not contains_unknowns(await future)
[Previous line repeated 20 more times]
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/resource.py", line 514, in do_register
resolver = await prepare_resource(res, ty, custom, remote, props, opts, typ)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/resource.py", line 124, in prepare_resource
serialized_props = await rpc.serialize_properties(
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc.py", line 207, in serialize_properties
result = await serialize_property(
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc.py", line 378, in serialize_property
value = await serialize_property(
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc.py", line 361, in serialize_property
future_return = await asyncio.ensure_future(awaitable)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 124, in get_value
val = await self._future
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 170, in run
value = await self._future
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 451, in gather_futures
return await _gather_from_dict(value_futures_dict)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 630, in _gather_from_dict
results = await asyncio.gather(*tasks.values())
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc_manager.py", line 68, in rpc_wrapper
result = await rpc
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 124, in get_value
val = await self._future
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/resource.py", line 685, in do_register_resource_outputs
serialized_props = await rpc.serialize_properties(outputs, {})
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc.py", line 207, in serialize_properties
result = await serialize_property(
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/runtime/rpc.py", line 375, in serialize_property
is_known = await output._is_known
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 168, in run
is_known = await self._is_known
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 99, in is_value_known
return await is_known and not contains_unknowns(await future)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi/output.py", line 215, in run
return await cast(Awaitable[U], transformed)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi_docker/docker.py", line 243, in build_and_push_image
build_result = await build_image(base_image_name, path_or_build, log_resource, cache_from)
File "/home/ubuntu/works/cloud/deployment/src/abcdef/venv/lib/python3.9/site-packages/pulumi_docker/docker.py", line 444, in build_image
raise ResourceError(
pulumi_docker.docker.ResourceError: No digest available for image 1234567890987.dkr.ecr.us-west-2.amazonaws.com/cloud/abcd-svc-4c4ac5e
E1011 06:09:05.598323428 59188 fork_posix.cc:76] Other threads are currently calling into gRPC, skipping fork() handlers
Output of pulumi about
CLI
Version 3.41.1
Go Version go1.19.1
Go Compiler gc
Plugins
NAME VERSION
aws 5.15.0
docker 3.4.1
python unknown
Host
OS ubuntu
Version 20.04
Arch x86_64
This project is written in python: executable='/home/ubuntu/works/cloud/deployment/src/abcdapp/venv/bin/python3' version='3.9.5
'
TYPE URN
pulumi:pulumi:Stack urn:pulumi:staging-accountid::abcdapp::pulumi:pulumi:Stack::abcdapp-staging-accountid
pulumi:providers:aws urn:pulumi:staging-accountid::abcdapp::pulumi:providers:aws::default
docker:image:Image urn:pulumi:staging-accountid::abcdapp::docker:image:Image::cloud/abcdapp-svc
pulumi:providers:aws urn:pulumi:staging-accountid::abcdapp::pulumi:providers:aws::default_5_15_0
aws:ecr/repository:Repository urn:pulumi:staging-accountid::abcdapp::aws:ecr/repository:Repository::cloud/abcdapp-svc
aws:cloudwatch/logGroup:LogGroup urn:pulumi:staging-accountid::abcdapp::aws:cloudwatch/logGroup:LogGroup::/ecs/abcdapp-svc
aws:ecr/lifecyclePolicy:LifecyclePolicy urn:pulumi:staging-accountid::abcdapp::aws:ecr/lifecyclePolicy:LifecyclePolicy::abcdapp-svc-lifecycle-policy
aws:lb/targetGroup:TargetGroup urn:pulumi:staging-accountid::abcdapp::aws:lb/targetGroup:TargetGroup::tg-abcdapp-svc
aws:iam/role:Role urn:pulumi:staging-accountid::abcdapp::aws:iam/role:Role::abcdapp-svc-exec-role
aws:iam/role:Role urn:pulumi:staging-accountid::abcdapp::aws:iam/role:Role::abcdapp-svc-task-role
aws:iam/rolePolicyAttachment:RolePolicyAttachment urn:pulumi:staging-accountid::abcdapp::aws:iam/rolePolicyAttachment:RolePolicyAttachment::abcdapp-svc-exec-policy
aws:iam/rolePolicyAttachment:RolePolicyAttachment urn:pulumi:staging-accountid::abcdapp::aws:iam/rolePolicyAttachment:RolePolicyAttachment::abcdapp-svc-exec-ssm-access-policy
aws:iam/rolePolicyAttachment:RolePolicyAttachment urn:pulumi:staging-accountid::abcdapp::aws:iam/rolePolicyAttachment:RolePolicyAttachment::abcdapp-svc-ecs-access-policy
aws:ec2/securityGroup:SecurityGroup urn:pulumi:staging-accountid::abcdapp::aws:ec2/securityGroup:SecurityGroup::abcdapp-svc-secgrp
aws:iam/rolePolicyAttachment:RolePolicyAttachment urn:pulumi:staging-accountid::abcdapp::aws:iam/rolePolicyAttachment:RolePolicyAttachment::abcdapp-svc-ssm-access-policy
aws:ec2/securityGroup:SecurityGroup urn:pulumi:staging-accountid::abcdapp::aws:ec2/securityGroup:SecurityGroup::abcdapp-svc-secgrp-db
aws:lb/loadBalancer:LoadBalancer urn:pulumi:staging-accountid::abcdapp::aws:lb/loadBalancer:LoadBalancer::lb-abcdapp-svc
aws:lb/listener:Listener urn:pulumi:staging-accountid::abcdapp::aws:lb/listener:Listener::lis-abcdapp-svc
aws:rds/instance:Instance urn:pulumi:staging-accountid::abcdapp::aws:rds/instance:Instance::abcdapp-svc-rds
Backend
Name pulumi.com
URL https://app.pulumi.com/peter6
User peter6
Organizations peter6
Dependencies:
NAME VERSION
common-variables 1.4.4
coverage 6.4.4
deployment 1.4.0
mock 4.0.3
pip 22.2.2
pkg_resources 0.0.0
pytest 7.1.3
requests 2.28.1
setuptools 65.3.0
wheel 0.37.1
Pulumi locates its logs in /tmp by default
Use pulumi-docker==3.1.0 solves the problem.
I'm trying to use fastapi connect to Postgresql with async,but I got a NotimplementError,
It's seems the coderecord = await objects.get(test5, orderId=result['orderId'])
cause this problem.
but I don't know how to fixed it
there is some solution in network,but it did'n work
import platform
import asyncio
if platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
*code
import peewee_async
import peewee_asyncext
from fastapi import FastAPI
from playhouse.postgres_ext import *
db = peewee_asyncext.PooledPostgresqlExtDatabase(
database = 'postgres',
host = '127.17.0.2',
port = '5432',
user = 'postgres',
password = 1234,
register_hstore = False,
max_connections = 20,
connect_timeout = 3
)
objects = peewee_async.Manager(database =db)
db.set_allow_sync = False
class test5(Model):
orderId = FixedCharField(primary_key = True)
transactionId = FixedCharField()
class Meta:
database = db
table_name = 'test'
app = FastAPI()
#app.post("/test")
async def test():
result = {
"orderId":"test",
"transactionId":"123"
}
try:
record = await objects.get(test5, orderId=result['orderId'])
except Exception as e:
if str(e) == "":
await objects.execute(test5.insert(result))
return result
*request
import requests,json
data={}
url='http://127.0.0.1:8000/test'
r=requests.post(url,json.dumps(data))
print(r.text)
*error
Future exception was never retrieved
future: <Future finished exception=NotImplementedError()>
Traceback (most recent call last):
File "D:\Python\lib\site-packages\peewee_async.py", line 852, in connect_async
await conn.connect()
File "D:\Python\lib\site-packages\peewee_async.py", line 1014, in connect
self.pool = await aiopg.create_pool(
File "D:\Python\lib\site-packages\aiopg\pool.py", line 300, in from_pool_fill
await self._fill_free_pool(False)
File "D:\Python\lib\site-packages\aiopg\pool.py", line 336, in _fill_free_pool
conn = await connect(
File "D:\Python\lib\site-packages\aiopg\connection.py", line 65, in connect
connection = Connection(
File "D:\Python\lib\site-packages\aiopg\connection.py", line 772, in __init__
self._loop.add_reader(
File "D:\Python\lib\asyncio\events.py", line 504, in add_reader
raise NotImplementedError
NotImplementedError
Future exception was never retrieved
future: <Future finished exception=NotImplementedError()>
Traceback (most recent call last):
File "C:\Users\user\Desktop\test\others\.\test5.py", line 39, in test
record = await objects.get(test5, orderId=result['orderId'])
File "D:\Python\lib\site-packages\peewee_async.py", line 166, in get
await self.connect()
File "D:\Python\lib\site-packages\peewee_async.py", line 302, in connect
await self.database.connect_async(loop=self.loop, timeout=self._timeout)
File "D:\Python\lib\site-packages\peewee_async.py", line 852, in connect_async
await conn.connect()
File "D:\Python\lib\site-packages\peewee_async.py", line 1014, in connect
self.pool = await aiopg.create_pool(
File "D:\Python\lib\site-packages\aiopg\pool.py", line 300, in from_pool_fill
await self._fill_free_pool(False)
File "D:\Python\lib\site-packages\aiopg\pool.py", line 336, in _fill_free_pool
conn = await connect(
File "D:\Python\lib\site-packages\aiopg\connection.py", line 65, in connect
connection = Connection(
File "D:\Python\lib\site-packages\aiopg\connection.py", line 772, in __init__
self._loop.add_reader(
File "D:\Python\lib\asyncio\events.py", line 504, in add_reader
raise NotImplementedError
NotImplementedError
*Windows version info:
Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)] on
win32
Windows 10 Pro, version 20H2, OS build 19042.1526
I am getting TypeError, when I try to delete Warehouse instance.
Note: If I delete Shop instance, Warehouse under that Shop needs be deleted, that's why I used on_delete=models.CASCADE.
class Warehouse(models.Model):
"""Warehouse model"""
name = models.CharField(max_length=255)
shop = models.ForeignKey(Shop, on_delete=models.CASCADE)
class WarehouseViewSet(viewsets.ModelViewSet):
"""Viewset"""
queryset = models.Warehouse.objects.all()
serializer_class = serializers.WarehouseSerializer
Error:
TypeError: 'NoneType' object is not callable
[14/Feb/2021 22:10:46] "DELETE /api/v1/shop/warehouse/2/ HTTP/1.1" 500 113266
Internal Server Error: /api/v1/shop/warehouse/2/
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Python38\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python38\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python38\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Python38\lib\site-packages\rest_framework\viewsets.py", line 114, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Python38\lib\site-packages\rest_framework\views.py", line 505, in dispatch
response = self.handle_exception(exc)
File "C:\Python38\lib\site-packages\rest_framework\views.py", line 465, in handle_exception
self.raise_uncaught_exception(exc)
File "C:\Python38\lib\site-packages\rest_framework\views.py", line 476, in raise_uncaught_exception
raise exc
File "C:\Python38\lib\site-packages\rest_framework\views.py", line 502, in dispatch
response = handler(request, *args, **kwargs)
File "C:\Python38\lib\site-packages\rest_framework\mixins.py", line 91, in destroy
self.perform_destroy(instance)
File "C:\Python38\lib\site-packages\rest_framework\mixins.py", line 95, in perform_destroy
instance.delete()
File "C:\Python38\lib\site-packages\django\db\models\base.py", line 921, in delete
collector.collect([self], keep_parents=keep_parents)
File "C:\Python38\lib\site-packages\django\db\models\deletion.py", line 224, in collect
field.remote_field.on_delete(self, field, sub_objs, self.using)
Found the solution. I did not handle on_delete for Children model.
SOLUTION
class WarehouseChildren(models.Model):
data = models.PositiveIntegerField(default=0)
warehouse = models.ForeignKey(Warehouse, on_delete=models.SET_NULL, null=True)
or
class WarehouseChildren(models.Model):
data = models.PositiveIntegerField(default=0)
warehouse = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
google.api_core.exceptions.ServiceUnavailable: 503 Deadline Exceeded
using python 3.7 ,google-cloud-pubsub ==1.1.0 publishing data on topic. In my local machine it's working perfectly fine and able to publish data on that topic and also able to pull data from that topic through subscriber.
but don't understand it's not working when i deploy the code on server and it's failing with INLINE ERROR however when i explicitly call the publisher method on server it's publishing fine over server box also.code which is failing at below line while publishing:
future = publisher.publish(topic_path, data=data)
**ERROR:2020-02-20 14:24:42,714 ERROR Failed to publish 1 messages.**
Trackback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
return callable_(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 826, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/usr/local/lib/python3.7/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Deadline Exceeded"
debug_error_string = "{"created":"#1582208682.711481693","description":"Deadline Exceeded","file":"src/core/ext/filters/deadline/deadline_filter.cc","file_line":69,"grpc_status":14}"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/google/api_core/retry.py", line 184, in retry_target
return target()
File "/usr/local/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 Deadline Exceeded
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/publisher/_batch/thread.py", line 219, in _commit
response = self._client.api.publish(self._topic, self._messages)
File "/usr/local/lib/python3.7/site-packages/google/cloud/pubsub_v1/gapic/publisher_client.py", line 498, in publish
request, retry=retry, timeout=timeout, metadata=metadata
File "/usr/local/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in call
return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func
on_error=on_error,
File "/usr/local/lib/python3.7/site-packages/google/api_core/retry.py", line 206, in retry_target
last_exc,
File "", line 3, in raise_from
google.api_core.exceptions.RetryError: Deadline of 60.0s exceeded while calling functools.partial(.error_remapped_callable at 0x7f67d064e950>
You should try to chunk your data in reasonable sized chunks (max_messages) and don't forget to add a done callback.
# Loop over json containing records/rows
for idx, row in enumerate(rows_json):
publish_json(row, idx, rowmax=len(rows_json), topic_name)
# Publish messages asynchronous
def publish_json(msg, rowcount, rowmax, topic_project_id, topic_name):
batch_settings = pubsub_v1.types.BatchSettings(max_messages=100)
publisher = pubsub_v1.PublisherClient(batch_settings)
topic_path = publisher.topic_path(topic_project_id, topic_name)
future = publisher.publish(
topic_path, bytes(json.dumps(msg).encode('utf-8')))
future.add_done_callback(
lambda x: logging.info(
'Published msg with ID {} ({}/{} rows).'.format(
future.result(), rowcount, rowmax))
)
I have some problem with pool.acquire() and closed connection in pool.
Setting on PG Server set connection timeout to 120 second. When i use pool.acquire() it is raise error because connection is closed:
Sleep 150
Traceback (most recent call last):
File "test.py", line 21, in <module>
loop.run_until_complete(test_select())
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py", line 337, in run_until_complete
return future.result()
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "test.py", line 10, in test_select
async with pool.acquire() as conn:
File "/usr/local/lib/python3.5/site-packages/aiopg/utils.py", line 116, in __aenter__
self._conn = yield from self._coro
File "/usr/local/lib/python3.5/site-packages/aiopg/pool.py", line 170, in _acquire
assert not conn.closed, conn
AssertionError: <aiopg.connection.Connection object at 0x106f7df98>
and code
import asyncio
import aiopg
dsn = 'dbname=dbname user=user password=password host=127.0.0.1'
async def test_select():
async with aiopg.create_pool(dsn) as pool:
print("Sleep 150")
await asyncio.sleep(150)
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 1")
ret = []
async for row in cur:
ret.append(row)
assert ret == [(1,)]
print("ALL DONE")
loop = asyncio.get_event_loop()
loop.run_until_complete(test_select())
How to solve this problem.
Thanks!