0

I need to run

curl -H "Accept: application/json+v6" -H "x-api-key: <your_api_key>" \https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests\?registration=ZZ99ABC

In Python 2.7. I've looked into using requests but I'm unsure how to structure it specifically for the above command.

Help appreciated

  • Have a look at [this answer](https://stackoverflow.com/a/7933546/1409704) - it recommends using `urllib2`, adding the headers you need, as well as reading the response. – mids Mar 22 '19 at 15:24
  • 1
    Have you already tried https://curl.trillworks.com to get an idea for using the requests library? – mrks Mar 22 '19 at 15:30

1 Answers1

0

To break down your requirements, you need to:

  • Perform a request to a url (to the MOT service)
  • Include some headers (the -H params to curl)

You can easily do those things using requests:

import request

url = "https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests?registration=ZZ99ABC"
headers = {
    "Accept": "application/json+v6",
    "x-api-key": "your-key",

}

response = requests.get(url, headers=headers)
Geekfish
  • 2,173
  • 23
  • 28