Skip to content

RuntimeError: builder error: top-level serializer supports only maps and structs #111

@travess0

Description

@travess0

Description

When trying to send a POST request with a simple string using primp.post, the following error occurs:

RuntimeError: builder error: top-level serializer supports only maps and structs

Caused by:
    top-level serializer supports only maps and structs

How to Reproduce

Flask Test Server

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/', methods=['POST'])
def home():
    raw_data = request.get_data(as_text=True)
    
    if not raw_data:
        return jsonify({"error": "no data received"}), 400

    return jsonify({
        "string": raw_data,
    }), 200

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=3000, debug=True)

Works with curl:

curl -X POST --data "isastr" http://localhost:3000

Works with requests:

import requests

response = requests.post(
    url="http://localhost:3000", 
    data="isastr"
)

print(response.json())

Fails with primp:

import primp

response = primp.post(
    url="http://localhost:3000", 
    data="isastr"  # this causes the error
)

print(response.json())

It would be great if the library could support sending plain strings as the body of a POST request (similar to how requests handles it), or perhaps provide a more descriptive error message to help clarify the limitation. Totally understand if this is out of scope

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions