You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将CSV经纬度参数逐次传入HTTP请求批量调用接口?

批量调用HTTP接口处理CSV位置数据

实现思路

  • 读取CSV文件,逐行解析纬度(Latitude)和经度(Longitude)参数
  • 对每一组位置参数,拼接完整的HTTP请求URL
  • 按顺序发起GET请求,完成接口调用

Python 实现代码

import csv
import requests

# 接口基础URL,预留参数占位符
BASE_URL = "https://api.drivevegas.k8.devfactory.com/rest/acdr?latitude={latitude}&longitude={longitude}&heading=0&speed=0&course=90&sequence=1670427622&carCategories=REGULAR"

# 读取CSV文件并处理
with open('locations.csv', 'r', newline='', encoding='utf-8') as csvfile:
    reader = csv.DictReader(csvfile)
    for row_num, row in enumerate(reader, start=1):
        try:
            # 获取经纬度参数
            latitude = row['Latitude']
            longitude = row['Longitude']
            # 拼接完整请求URL
            request_url = BASE_URL.format(latitude=latitude, longitude=longitude)
            # 发起GET请求
            response = requests.get(request_url)
            # 输出请求状态和结果(可根据需求调整)
            print(f"第 {row_num} 条请求 - 状态码: {response.status_code}, 响应内容: {response.text[:100]}...")
            # 可添加延迟避免请求过于频繁
            # time.sleep(1)
        except Exception as e:
            print(f"第 {row_num} 条请求处理失败: {str(e)}")

使用说明

  1. 将你的CSV数据保存为locations.csv,确保表头为Latitude,Longitude
  2. 安装依赖包:pip install requests
  3. 运行脚本即可按顺序完成所有接口调用

内容的提问来源于stack exchange,提问作者Snehal Matharu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 23:00:57