Hi!
API weather/v1/stations works fine with Python 3.13.2 on a PC, but
with MicroPython ESP32_GENERIC_C3-20241129-v1.24.1 on a ESP32-C3
microcontroller I get error 406 Not Acceptable "Use of gzip
compression is required with Accept-Encoding: gzip header."
The error is probably caused by MicroPython limitations, but is there
any workaround that could solve the problem? Any HTTP headers or other
APIs? I want to get the temperature of a road wheather station (for
example 2020 Kähkönen).
In Python 3.13.2:
$ python
Python 3.13.2 (main, Feb 4 2025, 00:00:00) [GCC 14.2.1 20250110 (Red
Hat 14.2.1-7)] on linux
>>> import requests
>>> url = '
https://tie.digitraffic.fi/api/weather/v1/stations/2020/data'
>>> headers = {'Digitraffic-User': 'dotcomconsulting/tiesaa-Pori-3'}
>>> response = requests.get(url,headers=headers)
>>> response.status_code
200
>>> response.reason
'OK'
>>> response.headers
{'Content-Type': 'application/json;charset=UTF-8',
'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date':
'Tue, 15 Apr 2025 09:23:06 GMT', 'Server': 'openresty',
'Last-Modified': 'Tue, 15 Apr 2025 09:20:10 GMT', 'ETag':
'W/"09f42986e01c2306e4bebc097160cff60"', 'Expires': 'Tue, 15 Apr 2025
09:24:06 GMT', 'Cache-Control': 'max-age=60',
'access-control-allow-origin': '*', 'access-control-allow-methods':
'GET, POST, OPTIONS', 'access-control-allow-headers':
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Digitraffic-User',
'access-control-expose-headers':
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Digitraffic-User',
'Content-Encoding': 'gzip', 'X-Cache': 'Miss from cloudfront', 'Via':
'1.1
14b5d848e0a4cab1de054891ea1e787c.cloudfront.net (CloudFront)',
'X-Amz-Cf-Pop': 'HEL51-P1', 'Alt-Svc': 'h3=":443"; ma=86400',
'X-Amz-Cf-Id': '67LEquPoJdsZmDbo3Uyjg7BjMmfh6RqcG9I36LhifjvONyR3W0fC7g=='}
In MicroPython 1.24.1 on ESP32-C3:
(the first lines are identical as above until this:)
>>> response.status_code
406
>>> response.reason
b'Not Acceptable'
>>> response.headers
{'Vary': 'Origin', 'Connection': 'close', 'Content-Length': '70',
'Via': '1.1
1be5216f770ec05deb91e9e25b61b898.cloudfront.net
(CloudFront)', 'X-Cache': 'Miss from cloudfront', 'X-Amz-Cf-Pop':
'HEL51-P1', 'Server': 'CloudFront', 'Alt-Svc': 'h3=":443"; ma=86400',
'X-Amz-Cf-Id': 'AVTra_4NUASUqg3TDQcLxIc9np2vn7V1fGqCEXRUTomDTefEdurI_g==',
'Date': 'Tue, 15 Apr 2025 09:20:33 GMT'}
>>> response.text
'Use of gzip compression is required with Accept-Encoding: gzip header.'
I have tried the following header values in my request but the result
is always the same:
'Accept-Encoding': 'gzip'
'Accept-Encoding': 'identity'
'Accept-Encoding': 'deflate'
'Accept-Encoding': '*'
Regards, JJ