Sendin data to firebase

Hey, i am using this code to send data to firebase from portenta h7 but getting this error.

b’HTTP/1.1 400 Bad Request\r\nServer: nginx\r\nDate: Tue, 18 Apr 2023 15:02:30 GMT\r\nContent-Type: text/html\r\nContent-Length: 150\r\nConnection: close\r\nStrict-Transport-Security: max-age=31556926; includeSubDomains; preload\r\n\r\n\r\n400 Bad Request\r\n\r\n

400 Bad Request

\r\n
nginx\r\n\r\n\r\n’

on this code

import usocket as socket
import json
import network

Connect to Wi-Fi

SSID=‘’ # Network SSID
KEY=‘’ # Network key
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print(‘Connecting to Wi-Fi…’)
sta_if.active(True)
sta_if.connect(SSID, KEY)
while not sta_if.isconnected():
pass
print(‘Connected to Wi-Fi:’, sta_if.ifconfig())

Firebase credentials

firebase_host = ‘’
firebase_secret = ‘’ # replace with your Firebase secret

Data to be sent

data = {‘name’: ‘John Doe’, ‘age’: 30}

Send data to Firebase

url = ‘https://{firebase_host}/data.json?auth={firebase_secret}’.format(
firebase_host=firebase_host, firebase_secret=firebase_secret)

headers = {‘Content-Type’: ‘application/json’}
payload = json.dumps(data)

sock = socket.socket()
addr = socket.getaddrinfo(firebase_host, 443)[0][-1]
sock.connect(addr)

sock.send(b"POST /data.json HTTP/1.0\r\n")
sock.send(b"Host: %s\r\n" % firebase_host.encode(‘utf-8’))
sock.send(b"Content-Length: %d\r\n" % len(payload))
sock.send(b"Content-Type: application/json\r\n")
sock.send(b"\r\n")
sock.send(payload.encode(‘utf-8’))

response = sock.recv(4096)
sock.close()

print(response)

Hi, I can’t debug your firebase code.