Description
Erreur lors de l'envoi des données: (-8576, 'MBEDTLS_ERR_X509_INVALID_FORMAT')
This is the type of error i get with my program in circuitpython (8.2.9) using PI Pico W and SSL.
SSL is used to secure communication between Pico W and a Flask server running on a Raspberry pi 4.
The certificate looks valid (no weird caracter), was put at the root of the pico W and was generated using this command : openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes.
I don't undertsand what's wrong with the format...
The code is as follows :
# Connexion au réseau WiFi en utilisant les variables d'environnement du fichier settings.toml
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
print("Connected to WiFi")
# Création d'une session de requête avec SSL context
ssl_context = ssl.create_default_context()
# Charger le certificat auto-signé
ssl_context.load_verify_locations('cert.pem')
# Création d'une session de requête en utilisant le pool de socket
pool = socketpool.SocketPool(wifi.radio)
http_session = requests.Session(pool, ssl_context)
# URL de l'API REST
url = 'https://*.*.*.*:*/insert_measurements' # i put stars bu ip is correct
....
# Envoi des données à l'API REST via une requête POST
try:
response = http_session.post(url, json=data)
print("Données envoyées avec succès, réponse:", response.json())
except Exception as e:
print("Erreur lors de l'envoi des données:", e)
The error I get comes at this point.
Any idea ?
The program does eveything but could not send the data to Flask.
Hope someone can help me find what's wrong here ...