Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sending json data from localhost Jupyter notebook to vue page

I have a localhost jupyter notebook python file which I’m trying to send data to my api/python/index.ts file and fetch said data from my index.vue page using useFetch('/api/python/') but am receiving a get request error

Using nuxt3

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Error message:

GET http://localhost:3000/api/python 405 (HTTP method is not allowed.)

code:

localhost python script

url = 'http://localhost:3000/api/python'

headers = {'Content-type': 'application/json'}

response = requests.post(url, json=top_3_json, headers=headers)

print(response.json())
{'status': 200, 'body': '{"surfboards": \[{"id": 22, "value": 0.04}, {"id": 45, "value": 0.04}, {"id": 46, "value": 0.03}\]}', 'headers': {'Content-Type': 'application/json'}}

‘/server/api/python/index.ts’

The request handler code
code source -https://nuxt.com/docs/guide/directory-structure/server#catch-all-route (#handling requests with body)

export default defineEventHandler(async (event) => {
    const body = await readBody(event)
    console.log(data)
    return { body }
})

console log output:

{"surfboards": [{"id": 22, "value": 0.04}, {"id": 45, "value": 0.04}, {"id": 46, "value": 0.03}]}

‘/pages/index.vue’

export default {

    setup() {
        
        const { data } = useFetch('/api/python/')

        return { data }

    }

In the browser console I receive this error message:

GET http://localhost:3000/api/python 405 (HTTP method is not allowed.)

The server-side file is returning the data but it cannot be accessed from the client side

Any help would be much appreciated,

Jack

>Solution :

In the Python script, you’re making a POST request.

The error message from your other code says you’re making a GET request, which the endpoint doesn’t handle (hence the 405 status code).

If the Python code is successful, then you should make a POST request in your other client, too.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading