0

I'm trying to use fastapi connect to Postgresql with async,but I got a NotimplementError,
It's seems the code
record = 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
VLAZ
  • 26,331
  • 9
  • 49
  • 67
timber
  • 1
  • The `NotImplemented` error is there to say well I know that I need to implement this to be compliant with the API but I haven't. It means either product is not enough mature and will implement it one day or the function is not available for good reason but the function is created to fulfil the API contract but cannot expose the functionality. In this case it seems the `add_reader` functionality is missing. – jlandercy Feb 23 '22 at 14:18
  • @jlandercy maybe this is version problems cause? it used to work and didn't show "NotimplementedError" , after I pip upgrade aiopg or something and uninstall anaconda this error show up. i was confusion . – timber Mar 04 '22 at 06:01
  • @jlandercy My friend help me find the way to fixed this problem, [link](https://stackoverflow.com/questions/58422817/jupyter-notebook-with-python-3-8-notimplementederror) thanks for ur help – timber Mar 12 '22 at 10:57

0 Answers0