I
I
itsLegend2021-04-05 14:51:47
Flask
itsLegend, 2021-04-05 14:51:47

How in Flask, to accept Cyrillic characters from the arguments in a get request?

I'm trying to get Cyrillic from the arguments, but so far unsuccessfully, I tried to do this:

def search_songs():
    phrases_ = (request.args.get('q')).encode('utf-8')
    phrases_ = phrases_.decode('utf-8')
    tracks_q = vk_audio.search(q=phrases_)
    count = 0
    data = []
    for track in tracks_q:
        if count == 30:
            break
        data.append({'artist': track['artist'],
                            'title': track['title'],
                            'url': track['url']})
        res = json.dumps(data,
                 sort_keys=True, ensure_ascii=False, indent=4, separators=(',', ': '))
        count = count + 1
    return(res)


unicodedecodeerror ascii codec can't encode charter \xd1 in position 48 ordinal not in range 128


But it still doesn't work, what could be wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question