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

In Python post request json file 404

It occurred ERROR 404…
I can’t understand what is wrong

json file

{"place_name": "대저생태공원", "img_url": "https://encrypted-tbn1.gstatic.com/licensed-image?q=tbn:ANd9GcRRT1TkNZMCkAaZ-tlwXX_XL9UiaDkew5BDsnf4cMMt086OaBhAHlPWGisM-7GOFRwNaXKpGvxhTQZHfwNoyvKRXQ", "score": 4.2, "description": 1679, "address": "부산 강서구 대저1동 2314-11"}

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

python code

import requests

# Api 호출
url = "https://f053a068dd0ea6.lhrtunnel.link/api/places"
response = requests.post(url= url, data='./j.json')
print(response)

api post code

app.post('/api/add', (req, res) => {
  const {place_name, score, description, img_url, address} = req.body;
  connection.query(`INSERT INTO place VALUES (0, "${place_name}", ${score}, "${description}", "${img_url}", "${address}");`, (error, rows) => {
    if(error) console.log(error);
    res.send(rows);
  })
})

help me!

>Solution :

You are using the wrong url.

You need to open the file and read the content otherwise you are sending ./j.json instead of the file content

import requests

with open('./j.json') as f :
    data = f.read()
# Api 호출
url = "https://f053a068dd0ea6.lhrtunnel.link/api/add"
response = requests.post(url= url, data=data)
print(response)
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