0

for instance i have the following

title = "some title"
name = "name"
headers = {
        'Content-Type': 'application/json',
        }
data = '{"title": title,"name":name,"action":"save"}'
response = requests.post('http://192.168.1.7:8080/news/save.json', headers=headers, data=data)

i want to post the title and the name to a database with those fields, and they both will keep on changing . I execute this statement and it works without any errors, but when i see my database, these fields arent there yet. If i hardcode the title and the name then it works fine.

2
  • Try printing your 'data' variable. You'll see you are not adding 'title' and 'name' to the 'data'. Commented Mar 12, 2019 at 9:22
  • Please provide more details about the expected output. Commented Mar 12, 2019 at 9:24

1 Answer 1

3
  • Not sure what does this have to do with curl
  • You are sending an hardcoded string that has nothing to do with the defined variables. You should create a json and send that:

    import json
    
    title = "some title"
    name = "name"
    headers = {
        'Content-Type': 'application/json',
        }
    data = json.dumps({"title": title, "name": name, "action":"save"})
    response = requests.post('http://192.168.1.7:8080/news/save.json', 
                             headers=headers, data=data)
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.