I
I
i_ikigai2020-08-18 00:17:24
Python
i_ikigai, 2020-08-18 00:17:24

When you open the created link in Yandex, on the iPhone, instead of spaces,% 20 is filled, but on the android it is normal. What is the problem and how to solve it?

async def process_callback_button1(callback_query: types.CallbackQuery):
    genre = callback_query.data
    random_film = handlers.films(genre)
    await bot.answer_callback_query(callback_query.id)
    await bot.send_message(callback_query.from_user.id, f"{search}", reply_markup=InlineKeyboardMarkup().add(
        InlineKeyboardButton(text=f'{random_film}',
                             url=f'https://yandex.ru/search/?text={random_film}')))


def films(genre):
    with open('films_genre_dict.json', encoding='utf-8') as f:
        dict_films = json.load(f)
        s = random.choice(dict_films[f'{genre}'])
    return f'{s[0]} {s[1]}'


spoiler
На айфоне5f3af36ebddc3918985383.jpeg


spoiler
На андроиде5f3af39d1e491788001450.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-08-18
@SoreMix

As correctly said above, this is called URL Encoding. Encode your text in advance yourself, then everything will be fine.

import urllib.parse

def films(genre):
    with open('films_genre_dict.json', encoding='utf-8') as f:
        dict_films = json.load(f)
        s = random.choice(dict_films[f'{genre}'])
    return urllib.parse.quote(f'{s[0]} {s[1]}')

ps
f'{genre}'

f"{search}"

f'{random_film}'

why???

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question