A
A
agent_22032021-10-27 21:40:40
Python
agent_2203, 2021-10-27 21:40:40

How to send a picture to bottle and accept it via post request?

How can bottle in python3 respond to a post request with a picture and json information?
Right now I am sending and receiving json response like this

resp = post(
    f'http://{ip}:5000/', 
    data=dumps({
        "method": "some_method",
        "arg1": arg1, "arg2": arg2
    })
).json()


And accordingly the server side

@route('/', method='POST')
def index(): 
    ip = request.environ.get('REMOTE_ADDR')
    if ip not in const.ACCESS_SERVERS:
        return {"status": "ERROR", "response": {"respond": "not access", "code": "-4"}}
    
    args = eval(request.body.getvalue().decode('utf-8'))
    return {"status": "OK", "response": {"respond": "some respond", "code": "17"}}
    
run(host=curr_ip, port=5000)


I need to send a picture in the same way, I googled it, but nowhere does it say how to send a file / picture in the response from bottle, maybe I missed something, can you tell me how to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
agent_2203, 2021-10-28
@agent_2203

In short, I solved the problem simply in two requests, separately returns json and separately bottle.static_file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question