0

Here is client:

data = b'48958695427097097402529251103137444756'
r = requests.post("http://127.0.0.1:5000", data=data)

Here is server:

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from flask import Flask, Response, request

app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def get_data():
    print('Recieved from client: {}'.format(request.data))
    return Response('We recieved something…')

if __name__ == ‘__main__’:
    app.run(debug=True)

Client send to server byte string, but server receive only: b'' Why?

And how make server receive entire byte string? Thank you.

Ada King
  • 11
  • 1
  • 1
  • 3

2 Answers2

0

your @app.route does not contain any method so you need to add

@app.route('/',methods=['POST'])

In order to understand how @app.route works, refer this

edited code of yours

from flask import Flask, Response, request

app = Flask(__name__)

@app.route('/', methods=['POST'])
def get_data():
    print('Recieved from client: {}'.format(request.data))
    return Response('We recieved something…')

if __name__ == '__main__':
    app.run(debug=True)
Januka samaranyake
  • 2,385
  • 1
  • 28
  • 50
  • There was methods, I don't understand why it disappeared after pasting here, now I edited it in my post and it's correct, but code does not work anyway. – Ada King Nov 19 '16 at 08:33
  • Please remember to click "Mark as Answer" the responses that resolved your issue. This can be beneficial to other community members reading this thread. – Januka samaranyake Nov 25 '16 at 05:18
0

You are missing the end of the line in:

@app.route('/', methods=['POST'])

After this minor fix, your code should work.

Yuval Pruss
  • 8,716
  • 15
  • 42
  • 67