Skip to content

urequests can't count content-length #1024

Closed
@bvajk

Description

@bvajk
resp = urequests.post(self.push_url, data=data, headers=self.headers)
resp.close()
self.logger.warning("headers = {}, data({})({}) = {}".format(self.headers, type(data), len(data), data))
2025/06/15 18:26:40.006 [WARN] {"msg": "headers = {'Connection': 'close', 'Host': '192.168.1.100', 'Content-Type': 'application/json', 'Content-Length': '1954'}, data(<class 'str'>)(2123) = {\"streams\": [{\"values\":
 [[\"1750004784000000000\", \"2025/06/15 18:26:24.006 [INFO] {\\\"msg\\\": \\\"Gc collect scheduled\\\"}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"values\": [[
\"1750004784000000000\", \"2025/06/15 18:26:24.006 [INFO] {\\\"msg\\\": \\\"Initializing scheduling\\\"}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"values\": [[
\"1750004784000000000\", \"2025/06/15 18:26:24.006 [INFO] {\\\"msg\\\": \\\"Scheduling started\\\"}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"values\": [[\"175
0004784000000000\", \"2025/06/15 18:26:24.006 [INFO] {\\\"msg\\\": \\\"Started! Model is esp-c3-tent-metrics\\\"}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"val
ues\": [[\"1750004790000000000\", \"2025/06/15 18:26:30.006 [METRIC] {\\\"msg\\\": {\\\"name\\\": \\\"healthcheck\\\", \\\"free_memory\\\": 69216, \\\"uptime_ms\\\": 17778}}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"
tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"values\": [[\"1750004790000000000\", \"2025/06/15 18:26:30.006 [INFO] {\\\"msg\\\": \\\"Gc sweep complete\\\"}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-m
etrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"values\": [[\"1750004790000000000\", \"2025/06/15 18:26:30.006 [METRIC] {\\\"msg\\\": {\\\"before\\\": 68192, \\\"after\\\": 117008, \\\"name\\\": \\\"gc\\\", \\\"diff\\\": 4
8816}}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"values\": [[\"1750004790000000000\", \"2025/06/15 18:26:30.006 [METRIC] {\\\"msg\\\": {\\\"name\\\": \\\"tds\\
\", \\\"value\\\": 3.795254}}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"values\": [[\"1750004790000000000\", \"2025/06/15 18:26:30.006 [METRIC] {\\\"msg\\\": {
\\\"name\\\": \\\"water_temperature\\\", \\\"value\\\": \\\"26.63\\\"}}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}, {\"values\": [[\"1750004800000000000\", \"2025/06/15 18:26:40.006 [INFO] {\\\"msg\\\": \\\"Uploading logs to loki\\\"}\"]], \"stream\": {\"service\": \"iot\", \"job\": \"tent-metrics\", \"model\": \"esp-c3-tent-metrics\"}}]}"}

due to this I can't send some requests to my loki, is there any way to solve this? I also tried with data.encode("utf-8"), same length in both places, just the type is bytes, it would also help if I could overwrite the content-length in the passed headers to something like 1_000_000, but I can't, and not sending content-length at all would also solve the issue, but it doesn't seem possible.
Any tips on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions