Python Script for Vehicle Violation Record Query Using Alibaba Cloud API

This article demonstrates how to use Python's requests library to call the Alibaba Cloud vehicle violation query API, guiding users through obtaining a free test package, configuring request parameters and headers, handling responses, and displaying violation details or confirming no violations.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Script for Vehicle Violation Record Query Using Alibaba Cloud API

With the rapid development of the Internet, convenient queries such as vehicle violation record checks have become popular; this tutorial shows how to implement a vehicle violation query function using Python.

The data is accessed via the Alibaba Cloud API Marketplace, specifically the Tianyan data service, which provides a free test package allowing up to ten test requests.

After logging into Alibaba Cloud, select the free test package, purchase it, and obtain the AppCode needed for authentication.

Below is the complete Python implementation. import requests Prompt the user for vehicle information:

car_no = input("请输入如车牌号:")
car_type = input("请输入如车辆类型,大车输入01,小车输入02:")
engine_number = input("请输入如车辆引擎号:")
frame_number = input("请输入如车架号:")

Define the main function that builds the request and processes the response:

def main():
    """主函数"""
    # 请求网址
    url = "http://carwz.shumaidata.com/post/carwz"
    # 接口 appcode
    appcode = 'fd1dfdc3c97447f6b5259ebaf51808f7'
    # headers 信息
    headers = {'Authorization': f'APPCODE {appcode}'}
    # 请求数据
    data = {
        'car_no': car_no,
        'car_type': car_type,
        'engine_number': engine_number,
        'frame_number': frame_number
    }
    try:
        # 发送 post 请求
        response = requests.post(url, params=data, headers=headers)
        content = response.json()
        if content["code"] != '0':
            print("请求失败, 请检查您的输入信息")
            return
        carNo = content["result"]["carNo"]
        if content["result"]["vioNum"] == "0":
            print(f"您的车牌号{carNo}没有违章记录")
        else:
            print(f"您的车牌号{carNo}有如下违章记录")
            # 遍历违章记录
            for item in content["result"]["data"]:
                print("*" * 20)
                print(f"""
违章时间: {item["vioTime"]}
违章地点: {item["vioAddress"]}
违章原因: {item["vioAction"]}
罚款金额: {item["vioFine"]}
罚款扣分: {item["vioScore"]}
""")
    except Exception:
        print("请求异常")

if __name__ == '__main__':
    main()

The script sends a POST request with the vehicle details, checks the response code, and either reports that there are no violations or iterates through the returned violation records, printing the time, location, reason, fine amount, and penalty points for each.

Example interaction shows a user entering a license plate, vehicle type, engine number, and frame number, after which the program reports that the vehicle has no violation records.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonAPITutorialVehicle Violation
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.