Search code examples
pythonsslpostmanfastapi

Unable to reach backend made in FastAPI deployed on deta after their migration to Cloud, the issue seems to be relevant to SSL


I have built a small API / backend using Fast API in python, the backend was deployed on deta as micro, and it was working fine. After deta updated their system and converted to deta space, at that time I faced the problem. First of all, according to otheir instructions, I migrated my deta micro to deta space app using this guide https://deta.space/migration/guides/migrate-a-micro. The space app is online now at a URL. But the problem is that it is not working as expected.

If I click on the URL, it opens in webs browser, and gives a repsonse

`

{"detail":"Not Found"}

`

which is completely fine, my API should handle any random GET request without data, this way. But this is just one scenario. Technically, most of time, it has to handle POST request with some data, so when I try even to test the API in Postman or use it in my React Native Frontend, it gives unexpected errors.

On replicating the same URL with GET request in Postman, it doesnt give same results, rather the body is

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/auth_assets/favicon.png" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Authorization | Deta Space</title>
    <script defer data-domain='deta.space' src='https://plausible.io/js/plausible.js'></script>
    <script type="module" crossorigin src="/auth_assets/js/index-88ebf614.js"></script>
    <link rel="stylesheet" href="/auth_assets/css/index-718df3f8.css">
</head>

<body>
    <div id="app"></div>

</body>

</html>

and the Headers are as followsenter image description here

My concern is that it should give same response as in browser, when requested with Postman.

The problem was not faced with prior version of deta micro.

If you faced anything similar or if you know further how to setup FastAPI backend on deta space?

I tried to search on deta space docs, but unable to find a solution


Solution

  • I mistakenly omitted some information reading documentation, thats why this happened.

    Actually, when you migrate any Micro to Deta Space, it is only private as stated here https://fastapi.tiangolo.com/deployment/deta/#__tabbed_1_2:~:text=By%20default%2C%20every,accessible%20to%20you, so you have to setup public access. And that was the entire problem. The solution is written in the above link. Its is changing the Spacefile to following

    v: 0
    micros:
      - name: fastapi-deta
        src: .
        engine: python3.9
        public_routes:
          - "/*"
    

    Then run space push And here you go. The deta space will make your API public and now you can call it from anywhere like postman.