solorpower/crawler/tests/debug_cmsolar.py
haneulai e9a4f8e401 Add 'crawler/' from commit 'c9ed91d885f3c46efb98e98310a1882bb5936546'
git-subtree-dir: crawler
git-subtree-mainline: 8991b92ac8
git-subtree-split: c9ed91d885
2026-06-15 12:53:36 +09:00

52 lines
1.7 KiB
Python

import requests
from config import get_all_plants
from crawlers.cmsolar import fetch_data
from crawlers.base import create_session
def debug_cmsolar():
plants = get_all_plants()
target = next((p for p in plants if p['id'] == 'cmsolar-10'), None)
if not target:
print("Plant 10 not found")
return
print(f"Debug target: {target['name']}")
# Manually reproduce fetch_data logic to see raw response
auth = target.get('auth', {})
system = target.get('system', {})
login_id = auth.get('login_id', '') # config.py uses login_id? checking cmsolar.py it uses payload_id or auth get directly.
# config.py for cmsolar-10:
# 'auth': { 'login_id': 'sy7144', 'login_pw': 'sy7144', 'site_no': '834' }
# cmsolar.py fetch_data:
# login_id = auth.get('payload_id', '') -> THIS MIGHT BE WRONG if config keys are login_id
# Check config.py again for cmsolar-10 auth keys.
# Lines 154-158 in config.py:
# 'auth': { 'login_id': 'sy7144', 'login_pw': 'sy7144', 'site_no': '834' }
# cmsolar.py Lines 20-22:
# login_id = auth.get('payload_id', '')
# login_pw = auth.get('payload_pw', '')
# site_no = auth.get('site_no', '')
# WAIT! 'payload_id' vs 'login_id'.
# If the code expects 'payload_id' but config provides 'login_id', then login_id will be empty string.
# This might be the bug.
print(f"Auth keys in config: {list(auth.keys())}")
# Let's try to run fetch_data and catch exception
try:
result = fetch_data(target)
print(f"Result: {result}")
except Exception as e:
print(f"Exception: {e}")
if __name__ == "__main__":
debug_cmsolar()