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

调用Get-Connector获取30天数据时JSON解码失败问题

问题:获取30天数据时触发JSONDecodeError错误

我用Python代码通过Get-Connector获取数据,查询15天数据时运行正常,但查询30天数据时触发以下错误:

Traceback (most recent call last):
  File "C:\source\repos\Cabman Get-All\Cabman Get-All\Cabman_Get_All.py", line 
  46, in <module>
    jsondata = json.loads(data.content)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfrap0\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra80\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

相关代码

用于获取数据并写入JSON文件的代码如下:

data = requests.get(url_data, headers = {'Host': 'services.%%%.com', 'Authorization': 'earer ' + acces_token})
status = data.status_code
jsondata = json.loads(data.content)
if status == 200:
    desired_dir = "B:\Cabman"
    full_path = os.path.join(desired_dir, x+'.json')
    with open(full_path, 'w') as f:
        json_string=json.dumps(jsondata, indent=4)
        f.write(json_string)
    print(x + " succesvol opgehaald.")
else: 
    print("Error at "+ x)
    print(status)

原始数据样例(敏感数据已掩码)

从Get-Connector获取的原始响应数据样例:

b'[{"shiftNumber":null,"egateShiftID":%%%,"weeknumber":6,"day":"zaterdag","hostId":7231,"driverCode":%%%,"driverName":"%%%","vehicleId":2751,"vehicleNr":"2270","licensePlate":"%%%","ShiftStart":"2023-02-11T07:58:33","FirstMovementTimeStamp":"2023-02-11T07:59:06","FirstTripTimeStamp":null,"diffLogonAndFirstMovement":0,"shiftStartLocation":{"latitude":0,"longitude":0},"LastMovementBeforeLogoffTimeStamp":"2023-02-11T08:00:36","ShiftEnd":"2023-02-11T08:01:47","diffLogoffAndLastMovement":1,"shiftEndLocation":{"latitude":%%%,"longitude":%%%},

生成的JSON文件样例(敏感数据已掩码)

小数据量下成功生成的JSON文件内容样例:

[
    {
        "shiftNumber": null,
        "egateShiftID": %%%,
        "weeknumber": 4,
        "day": "zondag",
        "hostId": 7231,
        "driverCode": %%%,
        "driverName": "%%%",
        "vehicleId": 2380,
        "vehicleNr": "1866",
        "licensePlate": "%%%",
        "ShiftStart": "2023-01-29T06:34:44",
        "FirstMovementTimeStamp": null,
        "FirstTripTimeStamp": null,
        "diffLogonAndFirstMovement": null,
        "shiftStartLocation": {
            "latitude": %%%,
            "longitude": %%%
        },
        "LastMovementBeforeLogoffTimeStamp": "2023-01-28T23:13:24",
        "ShiftEnd": "2023-01-29T06:59:14",
        "diffLogoffAndLastMovement": 465,
        "shiftEndLocation": {

问题集中在jsondata = json.loads(data.content)这一行,小数据量查询时代码运行正常,且requests.get没有返回错误状态码。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 15:01:12