0

(https://i.stack.imgur.com/xgoMx.jpg) I want to be able to pass a variable through to where the registration plate (AA19AAA) is

Overall, I want a function to check the number plate, therefore I need to pass a parameter through the function and use it in the payload, but I'm not sure how to actually pass a string to the inside of the payload.

I have tried using .format(...) to add things to the string, concatenating the variable into the payload, and another method similar to .format(...). However, if you believe any of these could be applicable, please don't hesitate to tell me as I may have made a mistake somewhere.

I hope some of you can assist me in this, I'm sorry if there is an incredibly simple solution to this, but I have tried a few, and feel that it is time to ask the professionals. Thank you so much

  • Please [don't post code/errors/data as images](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question). – Grismar Jan 23 '23 at 23:41
  • It's unclear what the problem is exactly? The image shows some code that has the rego in there, are you asking how you can create a template that allows you to call the web service with varying license plate numbers? You say you tried `.format()`, can you share what you tried and explain what happened, and what you expected/wanted? – Grismar Jan 23 '23 at 23:44
  • Does this answer your question? [Python Request Post with param data](https://stackoverflow.com/questions/15900338/python-request-post-with-param-data) – Woodford Jan 24 '23 at 00:05

1 Answers1

0

you have 2 options:

import requests
import json
payload = {'registrationNumber': some_var}
headers = {..., 'content': 'application/json'}
result = requests.post(url, headers = headers, data=json.dumps(payload))

or

import requests
headers = {...}
payload = {'registrationNumber': some_var}
result = requests.post(url, headers=headers, json=payload)
Niv Dadush
  • 64
  • 3