0

I have a simple Fastapi where am expecting python dictionary or json data. I can POST and GET data when running on local server. I hosted same api on https://deta.sh but i can only send GET request. POST request is returning status code 500. I tried hosting the same api on Heroku but i get status code 503

here is the sample code:

models.py

class DictType(TypeDecorator):
    impl = Text(SIZE)

    def process_bind_param(self, value, dialect):
        if value is not None:
            value = json.dumps(value)
        return value
    
    def process_result_value(self, value, dialect):
        if value is not None:
            value = json.dumps(value)
        return value

class DictTransactionBase(Base):
    __tablename__ = "Transactions"

    id = Column(Integer, primary_key=True, index=True)
    Body = Column(DictType())

schemas.py

class DictTransactionModel(BaseModel):
    Body: dict = {}

    class Config:
        orm_mode = True

main.py

@app.post('/api/v1/send/transactions/', status_code=status.HTTP_201_CREATED)
async def create_transaction(trans: schema.DictTransactionModel, db: Session = Depends(get_db)):
    results = models.DictTransactionBase(**trans.dict())
    db.add(results)
    db.commit()
    db.refresh(results)
    return results 

Above code runs on a local machine and POST data is saved to SQLite database. What would be the reason POST request is failing on the deployed API.

Chairman
  • 134
  • 1
  • 10
  • Either service should give you the actual log from your service so that you can see what is causing the service to fail - a 500 error indicates that there's been an Python exception raised or something similar. – MatsLindh May 17 '22 at 21:55
  • you should use module `logging` to write some information in file - to see which line is executed and what you have in variables. And you could also use `try/except` to catch error and save in `log`. – furas May 18 '22 at 02:22
  • to use module `SQLite` in Python it needs also C/C++ library `sqlite` and maybe server doesn't have it. – furas May 18 '22 at 02:24

1 Answers1

1

Unfortunately, micros only support read-only SQLite, which you could deploy with your code. You can use Deta Base instead of SQLite.

codemurt
  • 21
  • 4