How to make bold text in python query?

Question:

I’m doing a GET request using the Telegram Bot API.

I use the following query

telegram_msg = requests.get(f'https://api.telegram.org/<botname>:<botAPI>/sendPhoto?chat_id=<chatID>&parseMode=MarkdownV2&photo={link}&caption=*bold*{title}*nn{res}')

So I want the title to be bold. What am I doing wrong? Can someone help me please?

Asked By: Laura

||

Answers:

The issue is caused by the way you pass the parse_mode.


In your url there is:

&parseMode=MarkdownV2

But that should be

&parse_mode=MarkdownV2

After changing that, it works as expected with the following url/code/output:

https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=<CHAT-ID>&parse_mode=MarkdownV2&photo=http://placehold.jp/150x150.png&caption=*Foo*Bar
import requests

chatID='my-chat-id'
link='http://placehold.jp/150x150.png'
token='my-private-token'
caption='Example text'
telegram_msg = requests.get(f'https://api.telegram.org/bot{token}/sendPhoto?chat_id={chatID}&parse_mode=MarkdownV2&photo={link}&caption=*{caption}*')

Note: Make sure you’re using Python 3.6 or above to use f strings:

How do I put a variable’s value inside a string?


enter image description here

Answered By: 0stone0
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.