Ich versuche, auf die DVLA MOT -API zuzugreifen. Die OAuth 2-Token-Anfrage funktioniert und der Kontakt wird mit dem Server hergestellt, aber er gibt Fehlercode-Motten-BR-01 zurück.
{
"registration": "string",
"make": "Ford",
"model": "Focus",
"firstUsedDate": "2025-03-07",
"fuelType": "Petrol",
"primaryColour": "Silver",
"registrationDate": "2025-03-07",
"manufactureDate": "2025-03-07",
"engineSize": "1598",
"hasOutstandingRecall": "Yes",
"motTests": [
{
"completedDate": "2023-02-17T09:17:46.000Z",
"testResult": "PASSED",
"expiryDate": "2025-03-07",
"odometerValue": "string",
"odometerUnit": "MI",
"odometerResultType": "READ",
"motTestNumber": "string",
"dataSource": "DVSA",
"defects": [
{
"text": "string",
"type": "ADVISORY",
"dangerous": true
}
]
},
{
"completedDate": "2023-02-17T09:17:46.000Z",
"testResult": "PASSED",
"expiryDate": "2025-03-07",
"odometerValue": "string",
"odometerUnit": "KM",
"odometerResultType": "READ",
"motTestNumber": "string",
"dataSource": "DVA NI"
},
{
< /code>
Gibt jedoch nur eine Fehlermeldung zurück, in der es mit meiner Anfrage nicht stimmte wie folgt:{"requestId": "773c4d80-9538-4063-9450-0323221b562c","errorCode":"MOTHBR-01", "errorMessage":"Something is wrong with the request"}
< /code>
Hier ist mein Code (mit Anmeldeinformationen und API-Schlüssel zensiert): < /p>
import requests
# Step 1: Get the OAuth2 token
url = 'https://login.microsoftonline.com/ABC/oauth2/v2.0/token'
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
# Define the data for the POST request to get the access token
data = {
'grant_type': 'client_credentials',
'client_id': 'ABC',
'client_secret': 'ABC',
'scope': 'https://tapi.dvsa.gov.uk/.default'
}
# Send the POST request to get the token
response = requests.post(url, headers=headers, data=data)
# Check if the request was successful
if response.status_code == 200:
print('Access token:', response.json()['access_token'])
token = response.json()['access_token']
else:
print('Error:', response.status_code, response.text)
exit() # Exit if token request fails
# Step 2: Request MOT history for the vehicle
registration_number = 'ABC123' # Replace with the registration number of the vehicle you're querying
url2 = f'https://history.mot.api.gov.uk/v1/trade/vehicles/{registration_number}'
# Define the headers for the second request
headers2 = {
"Authorization": f"Bearer {token}", # Authorization header with access token
"X-API-Key": "API_KEY" # API Key
}
# Send the GET request to get the MOT history
response2 = requests.get(url2, headers=headers2) # GET request for MOT history
# Check if the request was successful
if response2.status_code == 200:
print('MOT History:', response2.json())
else:
print(f"Error: {response2.status_code} - {response2.text}")
Ich versuche, auf die DVLA MOT -API zuzugreifen. Die OAuth 2-Token-Anfrage funktioniert und der Kontakt wird mit dem Server hergestellt, aber er gibt Fehlercode-Motten-BR-01 zurück.[code]{ "registration": "string", "make": "Ford", "model": "Focus", "firstUsedDate": "2025-03-07", "fuelType": "Petrol", "primaryColour": "Silver", "registrationDate": "2025-03-07", "manufactureDate": "2025-03-07", "engineSize": "1598", "hasOutstandingRecall": "Yes", "motTests": [ { "completedDate": "2023-02-17T09:17:46.000Z", "testResult": "PASSED", "expiryDate": "2025-03-07", "odometerValue": "string", "odometerUnit": "MI", "odometerResultType": "READ", "motTestNumber": "string", "dataSource": "DVSA", "defects": [ { "text": "string", "type": "ADVISORY", "dangerous": true } ] }, { "completedDate": "2023-02-17T09:17:46.000Z", "testResult": "PASSED", "expiryDate": "2025-03-07", "odometerValue": "string", "odometerUnit": "KM", "odometerResultType": "READ", "motTestNumber": "string", "dataSource": "DVA NI" }, { < /code> Gibt jedoch nur eine Fehlermeldung zurück, in der es mit meiner Anfrage nicht stimmte wie folgt:{"requestId": "773c4d80-9538-4063-9450-0323221b562c","errorCode":"MOTHBR-01", "errorMessage":"Something is wrong with the request"} < /code> Hier ist mein Code (mit Anmeldeinformationen und API-Schlüssel zensiert): < /p> import requests
# Step 1: Get the OAuth2 token url = 'https://login.microsoftonline.com/ABC/oauth2/v2.0/token' headers = { 'Content-Type': 'application/x-www-form-urlencoded' }
# Define the data for the POST request to get the access token data = { 'grant_type': 'client_credentials', 'client_id': 'ABC', 'client_secret': 'ABC', 'scope': 'https://tapi.dvsa.gov.uk/.default' }
# Send the POST request to get the token response = requests.post(url, headers=headers, data=data)
# Check if the request was successful if response.status_code == 200: print('Access token:', response.json()['access_token']) token = response.json()['access_token'] else: print('Error:', response.status_code, response.text) exit() # Exit if token request fails
# Step 2: Request MOT history for the vehicle registration_number = 'ABC123' # Replace with the registration number of the vehicle you're querying url2 = f'https://history.mot.api.gov.uk/v1/trade/vehicles/{registration_number}'
# Define the headers for the second request headers2 = { "Authorization": f"Bearer {token}", # Authorization header with access token "X-API-Key": "API_KEY" # API Key }
# Send the GET request to get the MOT history response2 = requests.get(url2, headers=headers2) # GET request for MOT history
# Check if the request was successful if response2.status_code == 200: print('MOT History:', response2.json()) else: print(f"Error: {response2.status_code} - {response2.text}") [/code] Hier sind die API-Dokumente: https://documentation.history.mot.api.gov.uk/mot-history-api/api-specification/
Ich suche Hilfe für ein neues Problem, das ich gerade begegnet bin. Abrufen Sie Daten von jedem Server oder Dingen ab. Wann immer ich eine neue Seite öffne, sind nur Anfragen, die ich sehe, 1...
Ich versuche, von Legacy FCM (Firebase Cloud Messaging) API zur neuen FCM API V1 zu migrieren. Zu diesem Zweck habe ich ein paar Dinge auf der FCM -Seite gemäß der FCM -Dokumentation gemacht. Ich...
Dies ist mein erstes Projekt in Spring Boot (Noob), ich wollte diesen Google Mail -Senden -Dienst erstellen, ich habe Code von einem Repository erhalten, aber es funktioniert nicht, ich habe...
Ich habe eine Java 17 -App, in der ich versuche, eine Verbindung zu einem S3 -Speicherbehälter herzustellen, der auf einer NetApp -Site gehostet wird. Überprüfen Sie die Verbindung und machen Sie...