Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement of the send method #14

Open
Kirillka8996 opened this issue Apr 26, 2024 · 0 comments
Open

Improvement of the send method #14

Kirillka8996 opened this issue Apr 26, 2024 · 0 comments

Comments

@Kirillka8996
Copy link

Kirillka8996 commented Apr 26, 2024

When trying to send a message in another language with a line break using the send method, an error occurred: HTTP error: BadStatusLine
def send(self, chat_id, text): data = {'chat_id': chat_id, 'text': text} try: headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} url = f"{self.url}/sendMessage?chat_id={chat_id}&text={str(text).replace('\n', '%0A')}" response = urequests.post(url, headers=headers) response.close() return True except Exception as e: print("Error:", e) return False
In this code, I replaced the \n line breaks with URL-encoded %0A characters when generating the message body to be sent. This will help avoid problems with HTTP headers and request structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant