I was trying my first bot in bale messenger but I couldn't and faced this error. Is there any one here to help me?
2018-05-05 11:13:47,938 network.py:112 WARNING:"network connection disconnected."
2018-05-05 11:13:47,939 network.py:36 ERROR:"connect error: 500, message='Invalid response status'"
Traceback (most recent call last):
File "/home/ehsan/PycharmProjects/example_bots/venv/lib/python3.5/site-packages/balebot/connection/network.py", line 31, in connect self._ws = await self._session.ws_connect(self.construct_url())
File "/home/ehsan/PycharmProjects/example_bots/venv/lib/python3.5/site-packages/aiohttp/helpers.py", line 109, in __await__ ret = yield from self._coro
File "/home/ehsan/PycharmProjects/example_bots/venv/lib/python3.5/site-packages/aiohttp/client.py", line 465, in _ws_connect
headers=resp.headers) aiohttp.client_exceptions.WSServerHandshakeError: 500, message='Invalid response status'
it seems you use a websocket to connect your bot to server. and its a handshake error now. make sure the Token you have given from botfather was correct. If there is no problem with that it may be with your server address.
Related
WARNING: Invalid HTTP request received.
Traceback (most recent call last):
File "/home/ubuntu/MySQL_UI_Backend/venv/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 136, in handle_events
event = self.conn.next_event()
File "/home/ubuntu/MySQL_UI_Backend/venv/lib/python3.8/site-packages/h11/_connection.py", line 432, in next_event
raise RemoteProtocolError(
h11._util.RemoteProtocolError: Receive buffer too long
WARNING:uvicorn.error:Invalid HTTP request received.
Traceback (most recent call last):
File "/home/ubuntu/MySQL_UI_Backend/venv/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 136, in handle_events
event = self.conn.next_event()
File "/home/ubuntu/MySQL_UI_Backend/venv/lib/python3.8/site-packages/h11/_connection.py", line 432, in next_event
raise RemoteProtocolError(
h11._util.RemoteProtocolError: Receive buffer too long
The APIs are working fine locally but when I run it on EC2, I get the above error, the ports I have used are 7879 for the API server, 6869 for the frontend UI running on react
1.Make sure that the ports that you use are open at your security group settings.
2.Try changing the url from https to http
I just started writing a discord bot with python and although the code is very simple, I somehow keep getting a RuntimeError when trying to connect
I checked the token multiple times
would really appreciate it if someone could tell me what I did wrong
python Script:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=':')
#bot.event
async def on_ready():
print('bot is ready')
bot.run('my_token')
here is the traceback:
Traceback (most recent call last):
File "C:\Users\orang\Projects\PythonProjects\discord_lyrics_bot\venv\lib\site-packages\discord\http.py", line 293, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "C:\Users\orang\Projects\PythonProjects\discord_lyrics_bot\venv\lib\site-packages\discord\http.py", line 247, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File ".\main.py", line 12, in <module>
bot.run('Bxb-8dRGeYHYLFD5-IXGhNfY1TnX3kKA')
File "C:\Users\orang\Projects\PythonProjects\discord_lyrics_bot\venv\lib\site-packages\discord\client.py", line 718, in run
return future.result()
File "C:\Users\orang\Projects\PythonProjects\discord_lyrics_bot\venv\lib\site-packages\discord\client.py", line 697, in runner
await self.start(*args, **kwargs)
File "C:\Users\orang\Projects\PythonProjects\discord_lyrics_bot\venv\lib\site-packages\discord\client.py", line 660, in start
await self.login(*args, bot=bot)
File "C:\Users\orang\Projects\PythonProjects\discord_lyrics_bot\venv\lib\site-packages\discord\client.py", line 509, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\orang\Projects\PythonProjects\discord_lyrics_bot\venv\lib\site-packages\discord\http.py", line 297, in static_login
raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000217D658C670>
Traceback (most recent call last):
File "C:\Users\orang\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\orang\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\orang\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 719, in call_soon
self._check_closed()
File "C:\Users\orang\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
You're using the wrong discord token. First of all, you leaked your bot token
bot.run('Bxb-8dRGeYHYLFD5-IXGhNfY1TnX3kKA')
Regenerate your toek ASAP. Second, make sure you grab the token in the Bot Tab, and you don't get any of the other tokens. I can tell that the token is too short and is the wrong token.
I'm pretty sure you're using the client secret code, which is not your bot's token. What you have to do is go to applications in Discord's Developer Portal. Once you're there, click on your bot application, and then go to the Bot tab on the left (it will have a little puzzle piece next to it). Over there, you should see Click to Reveal Token under Build-A-Bot. You can either click that and copy what shows up, or you can simply click the Copy button which will automatically copy the bot's token for you. Please do not share your token with anyone, as it can be used to run other people's code if they have access to it. If you've already leaked it, just go ahead and click the Regenerate button, which will give you a new token for your bot, and it will null the older token so that nobody can use your bot anymore.
I'm trying to get every new message sent in a channel with python and then use the data to do some further processing. This is my code:
api_id = *******
api_hash = '**********************'
client = TelegramClient(
'session_name',
api_id,
api_hash,
)
client.start()
print(client.get_me().stringify())
client.send_message('someone', 'Hello! Talking to you from Telethon')
And this is the error that I get:
C:\Users\erfan\AppData\Local\Programs\Python\Python39\python.exe "C:/Users/erfan/Desktop/Boors py/main.py"
Traceback (most recent call last):
File "C:\Users\erfan\Desktop\Boors py\main.py", line 14, in <module>
client.start()
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\auth.py", line 133, in start
else self.loop.run_until_complete(coro)
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\auth.py", line 140, in _start
await self.connect()
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 516, in connect
if not await self._sender.connect(self._connection(
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\network\mtprotosender.py", line 123, in connect
await self._connect()
File "C:\Users\erfan\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\network\mtprotosender.py", line 249, in _connect
raise ConnectionError('Connection to Telegram failed {} time(s)'.format(self._retries))
ConnectionError: Connection to Telegram failed 5 time(s)
Process finished with exit code 1
Telegram is blocked by my country. So I use Lantern to have access to it and I can access web.telegram.com. I also tried using a mtproxy but got the same error.
I don't know which part of my code was wrong, but as I saw many people had the same problem, I decided to post my solution.
I could get telethon work very well with help of this article.
And as I said telegram is blocked in my country so I could use MTProxy with help of telethon documentation at this part: 2.2.5 Using MTProto Proxies.
try to run a basic scripts that adds members to a telegram group over pythoneverywhere server. I installed the main package which is telethon in the server. but i am getting the error in the image below. what am i not doing right?
error message is given below
21:02 ~/Villians TV/Villians5/TeleGram-Scraper-master $ python3 villians5.py
Traceback (most recent call last):
File "villians5.py", line 17, in <module>
client.connect()
File "/home/somti13/.local/lib/python3.8/site-packages/telethon/sync.py", line 39, in syncified
return loop.run_until_complete(coro)
File "/usr/lib/python3.8/asyncio/base_events.py", line 608, in run_until_complete
return future.result()
File "/home/somti13/.local/lib/python3.8/site-packages/telethon/client/telegrambaseclient.py", line 472, in connect
if not await self._sender.connect(self._connection(
File "/home/somti13/.local/lib/python3.8/site-packages/telethon/network/mtprotosender.py", line 125, in connect
await self._connect()
File "/home/somti13/.local/lib/python3.8/site-packages/telethon/network/mtprotosender.py", line 250, in _connect
raise ConnectionError('Connection to Telegram failed {} time(s)'.format(self._retries))
ConnectionError: Connection to Telegram failed 5 time(s)
The mtproto connection type for telegram does not work for free accounts on PythonAnywhere. Only http(s) connections out of PythonAnywhere will work for free accounts.
My email script is based on this script at Fine Frog. I'm using this script to send HTML log files from a number of remote machines using a variety of ISPs.
The attachment isn't being sent consistently, however. It does work 80% of the time, but I'm getting two types of weird behavior. The first is where the email isn't sent at all, but throws the error(s) you see below
Traceback (most recent call last):
File "/root/sapapps/reporter/usage_report.py", line 336, in ?
se.send_mail(['thinkwelldesigns#g1234.com'], cd.contact, 'dave#1234.com', report_subject, text_body, files=[report_name], bcc=[cd.tech_email])
File "/usr/lib/python2.4/site-packages/sap/send_email.py", line 61, in send_mail
mail_server.sendmail(server_addr, addresses, message.as_string())
File "/usr/lib/python2.4/smtplib.py", line 692, in sendmail
(code,resp) = self.data(msg)
File "/usr/lib/python2.4/smtplib.py", line 489, in data
self.send(q)
File "/usr/lib/python2.4/smtplib.py", line 319, in send
raise SMTPServerDisconnected('Server not connected')
smtplib.SMTPServerDisconnected: Server not connected
Or, on some machines, this error is raised.
reply: '421 Command timeout, closing transmission channel\r\n'
reply: retcode (421); Msg: Command timeout, closing transmission channel
data: (421, 'Command timeout, closing transmission channel')
send: 'rset\r\n'
Traceback (most recent call last):
File "/root/sapapps/reporter/usage_report.py", line 336, in ?
se.send_mail(['thinkwelldesigns#1234.com'], cd.contact, 'dave#1234.com', report_subject, text_body, files=[report_name], bcc=[cd.tech_email])
File "/usr/lib/python2.4/site-packages/sap/send_email.py", line 61, in send_mail
mail_server.sendmail(server_addr, addresses, message.as_string())
File "/usr/lib/python2.4/smtplib.py", line 694, in sendmail
self.rset()
File "/usr/lib/python2.4/smtplib.py", line 449, in rset
return self.docmd("rset")
File "/usr/lib/python2.4/smtplib.py", line 374, in docmd
return self.getreply()
File "/usr/lib/python2.4/smtplib.py", line 348, in getreply
line = self.file.readline()
File "/usr/lib/python2.4/socket.py", line 340, in readline
data = self._sock.recv(self._rbufsize)
socket.error: (104, 'Connection reset by peer')
In the second instance of weird behavior, the email is processed without error, the attachment goes along, but some data is stripped out of the HTML attachment in the emailing process. IOW, if you login to the remote machine, you'll find the original file intact, but the attached file is missed log entries.
I'm guessing that these issues are unrelated problems, but does anyone have some advice on how to most reliably send HTML attachments?
TIA,
Dave
I had a problem before using smtplib.SMTP, and figured out the email server required using an SSL connection. You could try using smtplib.SMTP_SSL if the regular call fails.
The first problem which raised one of the two following errors:
smtplib.SMTPServerDisconnected: Server not connected
or
socket.error: (104, 'Connection reset by peer')
was solved by switching to Gmail as the mail server.
The second error where part of HTML attachment was stripped out was solved by closing the report file before the email script processed...
html_report.close()
I'm a Python newbie. :-|