A
A
Anton Rosin2020-11-20 14:28:27
Flask
Anton Rosin, 2020-11-20 14:28:27

Error in Flask, Python server. How to decide?

Here is the server code:

The code
import json

from flask import Flask, request, Response, redirect

app = Flask(__name__)


@app.route('/')
def redirectToAuthInformation():
    return redirect(location='/info')

@app.route('/dah', methods=['GET'])
def dah():
    data = request.query_string[8:];
    return data;

if __name__ == '__main__':
    app.run()


On startup it gives the following error:
Mistake
ERROR in app: Exception on /dah [GET]
Traceback (most recent call last):
  File "C:\Users\Anton Rosin\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Anton Rosin\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Anton Rosin\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Anton Rosin\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "C:\Users\Anton Rosin\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Anton Rosin\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File ".\server.py", line 15, in dah
    return data;
TypeError: a bytes-like object is required, not 'str'


At least half an hour I sit and try to solve this problem.
I need to split a string of data passed by a GET request. (after splitting, you should get a list of type value1, value2, etc.)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Rosin, 2020-11-20
@Rosin886

the problem was solved after moving [8:] from data = request.query_string[8:]; in return data[8:];

R
Roman Mirilaczvili, 2020-11-20
@2ord

Try converting to byte array
return data.encode('utf-8');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question