0

I have an Http endpoint exposed as http://localhost:8080/test/api/v1/qc/{id} for delete, while making this API delete call I have to replace with the proper id

I tried below way using the requests module of python

param = {
  "id" : 1
}

requests.delete(url = http://localhost:8080/test/api/v1/qc/{id}, params=param)

This API call is breaking with the error

ValueError: No JSON object could be decoded.

How can I do this?

Hamada
  • 1,836
  • 3
  • 13
  • 27
Anshul Sharma
  • 1,018
  • 3
  • 17
  • 39
  • Maybe you meant `requests.delete(url=f"http://localhost:8080/test/api/v1/qc/{id}", params=param)`? If by id you meant the parameters id the it would probably be `requests.delete(url=f"http://localhost:8080/test/api/v1/qc/{param['id']}", params=param)` – Filip Jul 18 '20 at 10:08
  • @Filip, the way you are telling i need to change my endpoint url. – Anshul Sharma Jul 18 '20 at 11:25

1 Answers1

5

Your code can't run as-is. You need to quote your url string:

url = "http://localhost:8080/test/api/v1/qc/{id}"

Reading the docs for requests, the params only sends the dictionary param as the query string, so it'll only tack on ?id=1 to the end of the URL.

What you want is the {id} to get the value from the dictionary. You can look at this answer for various ways: How do I format a string using a dictionary in python-3.x?

You want something like

requests.delete(url = "http://localhost:8080/test/api/v1/qc/{id}".format(**param))

Foo L
  • 10,977
  • 8
  • 40
  • 52
  • Correct, params way could work for ?id= but my request has a placeholder in the url. by looking at the solution, given in the link provided by @Foo L, it looks like only replacing placeholder is the way, but i just wanted to know does requests methods have any direct way of doing this – Anshul Sharma Jul 18 '20 at 11:19
  • 1
    deserves more upvotes – Serhii Kushchenko Dec 29 '21 at 05:53