Help using Python to Communicate with the Fox API
Dear all.

I hope someone can help. I'm new to Python and API programming, but would like to use Python to communicate with the Fox cloud and get some info from my inverter.

My code keeps returning 'Illegal Signature'.
I've double checked the API key and the serial number for typo's.

The code is below, so any help would be gratefully received :-)
I've removed my API key and inverter serial number.

import requests
import hashlib
import time
import json

# -------------------------
API_KEY = 'xxxx' # From FoxESS Cloud API Management
DEVICE_SN = 'xxxx' # Like "H1-XXXXXXX"
# ------------------------

API_PATH = 'op/v1/device/real/query'
API_URL = f'https://www.foxesscloud.com/{API_PATH}'

def generate_signature(path, token, timestamp):
to_sign = f"{path}\r\n{token}\r\n{timestamp}"
print(f"\n[DEBUG] String to sign:\n{repr(to_sign)}")
sig = hashlib.md5(to_sign.encode('utf-8')).hexdigest()
print(f"[DEBUG] MD5 Signature: {sig}")
return sig

def get_data():
timestamp = str(int(time.time() * 1000))
signature = generate_signature(API_PATH, API_KEY, timestamp)

headers = {
'token': API_KEY,
'timestamp': timestamp,
'signature': signature,
'lang': 'en',
'Content-Type': 'application/json'
}

payload = {
'sn': DEVICE_SN,
'variables': [] # ← Get everything
}

print(f"\n[DEBUG] Headers:\n{json.dumps(headers, indent=2)}")
print(f"\n[DEBUG] Payload:\n{json.dumps(payload, indent=2)}")

response = requests.post(API_URL, headers=headers, data=json.dumps(payload))

print(f"\n[DEBUG] Status code: {response.status_code}")
print(f"[DEBUG] Response text:\n{response.text}")

try:
data = response.json()
pv_power = data.get('result', {}).get('pvPower', {}).get('value', 'N/A')
print(f"\nPV Power Output: {pv_power} W")
except Exception as e:
print("\n Error parsing response:", e)

get_data()


DEBUG LOG
---------
[DEBUG] String to sign:
'{path}\r\n{token}\r\n{timestamp}'
[DEBUG] MD5 Signature: 24c56d0c365016ecbc32503fab6048bc

[DEBUG] Headers:
{
"token": "xxxxx",
"timestamp": "1754005322469",
"signature": "24c56d0c365016ecbc32503fab6048bc",
"lang": "en",
"Content-Type": "application/json"
}

[DEBUG] Payload:
{
"sn": "xxxxx",
"variables": []
}

[DEBUG] Status code: 200
[DEBUG] Response text:
{"errno":40256,"msg":"Parameter could not be parsed correctly illegal signature"}

PV Power Output: N/A W
The program 'python3.13.exe' has exited with code 0 (0x0).
Re: Help using Python to Communicate with the Fox API
Had a quick look and the most obvious thing I can see is that you are using the python ‘f’ format to convert the string, you need to use ‘fr’ i.e. a raw string which treats ‘\’ (escape) characters as literals.

The OpenAPI docs are here https://www.foxesscloud.com/public/i18n ... e9H9BCT8#6 and there is a code sample shown which might help in setting it up.
Re: Help using Python to Communicate with the Fox API
There is a load of working code here:

https://github.com/TonyM1958/FoxESS-Cloud

You can just import the module and set a few variables and it will work. You don't need to write the code from scratch.
H1-6.0-E hybrid inverter
6 x HV2600 v2 batteries
16 x JA Solar 405w panels
7 x Tigo TS4-A-O optimisers
Post Reply