-1

I am looking for some guidance for my script. As you can see, I want to have user input enter the vehicle reg number. This would then need to sit in the end of the URL so user input can dictate which vehicle is called via the API.

import requests
import json
registration = str(input("What's your REG number? "))
url = "https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests/?registration=PJ66FKY"
payload = {}
headers = {
  'x-api-key': 'XXXXXXXXXXXXXXXXXXXXX',
  'Content-Type': 'application/json',
  'Cookie': 'visid_incap_1151098=RTIoGHIETUSrjaf5W7QCScxP2l4AAAAAQUIPAAAAAAAkfOLSmlzNbGFWSfE86hQh; nlbi_1151098=hrz6EkFnOlWdINdZsRy5CgAAAADwbuHnEYVAPG0gSttx0Nsd; incap_ses_869_1151098=w7M8LuMrFQob4OeqJlAPDM9R2l4AAAAAKnNYAG3p3JxlCSU27U1/Qw=='
}
response = requests.request("GET", url, headers=headers, data = payload)
#print(response.text.encode('utf8'))
print (json.dumps(response.json(), indent=4, sort_keys=True))
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
rodger
  • 1
  • Does this answer your question? [How do I put a variable inside a string?](https://stackoverflow.com/questions/2960772/how-do-i-put-a-variable-inside-a-string) – jonrsharpe Jun 05 '20 at 14:42
  • What is the question, actually? Is it the one answered by @jonrsharpe? – Amitai Irron Jun 05 '20 at 14:49

1 Answers1

0

As @jonrsharpe mentioned in the comments, you can use python's f-string formatting

import requests
import json
reg_num = str(input("What's your REG number? "))
url = f"https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests/?registration={reg_num}"
payload = {}
headers = {
  'x-api-key': 'XXXXXXXXXXXXXXXXXXXXX',
  'Content-Type': 'application/json',
  'Cookie': 'visid_incap_1151098=RTIoGHIETUSrjaf5W7QCScxP2l4AAAAAQUIPAAAAAAAkfOLSmlzNbGFWSfE86hQh; nlbi_1151098=hrz6EkFnOlWdINdZsRy5CgAAAADwbuHnEYVAPG0gSttx0Nsd; incap_ses_869_1151098=w7M8LuMrFQob4OeqJlAPDM9R2l4AAAAAKnNYAG3p3JxlCSU27U1/Qw=='
}
response = requests.request("GET", url, headers=headers, data = payload)
#print(response.text.encode('utf8'))
print (json.dumps(response.json(), indent=4, sort_keys=True))

The reg_num variable's value will be automatically while execution

bumblebee
  • 1,811
  • 12
  • 19