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.

3
  • 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. Commented May 17, 2022 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. Commented May 18, 2022 at 2:22
  • to use module SQLite in Python it needs also C/C++ library sqlite and maybe server doesn't have it. Commented May 18, 2022 at 2:24

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.