0

I'm trying to create a PUT request using the lib requests. The request is working properly when i send the data through POSTMAN, but it doesn't work with Python requests.

Here's what i've tried:

jsn = {'key 1' :'item 01', 'key 2' :'item 02', 'key 3' :'item 03'}
i = jsn
headers = {'Authorization-Token': token , 'User': user , 'App':'API' }
params = {'Content-Type': 'application/json'}
url = url
data = {'pedido':i}
request_put = requests.put(url, headers = headers, params = params, data = data)
print (request_put.text)

When i run the code i receive a message: <Response [200]> ""Couldn't locate key 3""

Any ideas on where i could have messed up?

  • In Postman you can [generate code from the request](https://learning.postman.com/docs/sending-requests/generate-code-snippets/). Does the Python PUT request work when you run the for the call that works in Postman? – Saaru Lindestøkke Feb 28 '23 at 18:11
  • Hello Saaru, i didn't understand your question, can you rephrase ? – matheusppedroso Feb 28 '23 at 18:14
  • You now wrote Python code yourself. You can ask Postman to write the Python code for you, for a specific request (as explained in the link). If you take the request that works in Postman, let Postman generate code for that and then try to run it, do you get the same error? – Saaru Lindestøkke Feb 28 '23 at 18:17
  • I've used the code POSTMAN generated, but now i've got a different error saying the the request didn't worked. I don't understand how because, i'm using the EXACTLY same code as POSTMAN – matheusppedroso Feb 28 '23 at 18:53
  • Well, in contrast to popular belief others can't simply see what's on your screen, so to receive any help you would need to show the code you use and the error you receive (and perhaps a screenshot of the working postman call) – Saaru Lindestøkke Feb 28 '23 at 19:20

0 Answers0