Skip to content

[Bug] It seems that fail to fetch LTE data from CelesTrak #19

@Hantingwithoutheart

Description

@Hantingwithoutheart

Problem Description

When running the TLE constellation tests, the program may crash during constellation generation because today’s JSON TLE data is not available, but the code still tries to write/read it as if it exists.
(1) To Reproduce

Run the code following the instruction.

  1. install uv
  2. create the venv
  3. remove the # before main in StarPerf.py
  4. commenting out the code related to XML_testing(optional)
  5. uv run StarPerf.py

(3) Actual Behavior

Starting StarPerf...
Starting TLE Constellations Testing
Test(01/16) : constellation generation
Traceback (most recent call last):
File "c:\Users\davis\Desktop\code\python\starperf\StarPerf_Simulator\StarPerf.py", line 90, in

main()
File "c:\Users\davis\Desktop\code\python\starperf\StarPerf_Simulator\StarPerf.py", line 26, in
ation_generation_test
constellation = constellation_configuration.constellatiTLE_constellation_test_cases() on_configuration(dT, constellation_name) f_Simulator\samples\TLE_constellation
File "c:\Users\davis\Desktop\code\python\starperf\StarPertion_test_casesf_Simulator\src\constellation_generation\by_TLE\constellatitest()on_configuration.py", line 24, in constellation_configuratif_Simulator\samples\TLE_constellation\on line 16, in constellation_generation_
DOWNLOAD_TLE_DATA.download_TLE_data(constellation_name)
on_configuration(dT, constellation_nam
File "c:\Users\davis\Desktop\code\python\starperf\StarPerf_Simulator\src\constellation_generation\by_TLE\download_TLf_Simulator\src\constellation_generatiE_data.py", line 92, in download_TLE_data tellation_configuration
file[formatted_date].create_dataset(formatted_date + "-json", data=json_TLE) f_Simulator\src\constellation_generati
UnboundLocalError: local variable 'json_TLE' referenced befataore assignment

Alternatives

copilot tells:
问题链路在 download_TLE_data.py 很清楚:

  1. 代码先请求 FORMAT=2le
  2. 紧接着又请求同一组的 FORMAT=json
  3. json_TLE 只在 response2.status_code == 200 时才赋值,见 download_TLE_data.py
  4. 但后面无论 JSON 请求是否成功,都会写 formatted_date + "-json",见 download_TLE_data.py

所以一旦出现这种情况:
2LE 请求成功了,但紧接着 JSON 请求因为“刚下载过、2 小时内不更新”被 403 拒绝,

就会发生你看到的异常:
json_TLE 没赋值,却被拿去写 HDF5,于是报 UnboundLocalError

更关键的是,本地缓存已经把这个结论坐实了。你现在的 tle.h5 里,今天的组 20260416 只有 20260416-2LE,没有 20260416-json。这正说明当时流程是:

  1. 2LE 已经下载成功并写入
  2. JSON 没写进去
  3. 程序在写 -json 数据集时崩了

而后续 satellite_to_shell_mapping.py 又强依赖当天的 -json 数据集,所以这个“半成品”状态还会影响你当天后面的重跑。

结论是:
根本原因不是 StarPerf.py,也不是测试入口本身,而是 download_TLE_data.py 的下载策略和异常处理有问题。它假设同一时刻连续下载 2lejson 一定都能成功,但 CelesTrak 实际上会因为 2 小时更新限制返回 403

如果你要,我下一步可以直接帮你修这个根因,通常会做这几件事:

  1. 给 JSON 请求也加明确的失败处理,不再让 json_TLE 未定义
  2. 避免写出只有 -2LE 没有 -json 的半成品组
  3. 如果当天本地缓存已经完整存在,就直接复用,不重复请求
  4. 在远端返回 403 且提示“2 小时未更新”时,优先读取本地已有数据而不是崩溃

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions