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"}
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!
CodePudding user response:
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)