Discord bot not running with heroku - heroku

I'm in the process of moving my discord bot from locally hosting to heroku and i seem to have everything down except for actually running it.
When I enable the python worker, it doesn't seem to bring my bot online.
I'm not sure why this would be the case. It's connected to my GitHub and the bot token is defined using the vars.
The build logs look normal but the app logs have some errors that I'm not sure how to fix, which I have to assume is the problem.
Application logs:
2022-04-15T05:10:52.792118+00:00 app[worker.1]: from .client import Client
2022-04-15T05:10:52.792127+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/client.py", line 53, in <module>
2022-04-15T05:10:52.792226+00:00 app[worker.1]: from .webhook import Webhook
2022-04-15T05:10:52.792234+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/webhook/__init__.py", line 12, in <module>
2022-04-15T05:10:52.792307+00:00 app[worker.1]: from .async_ import *
2022-04-15T05:10:52.792315+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/webhook/async_.py", line 52, in <module>
2022-04-15T05:10:52.792382+00:00 app[worker.1]: from ..channel import PartialMessageable
2022-04-15T05:10:52.792405+00:00 app[worker.1]: ImportError: cannot import name 'PartialMessageable' from 'discord.channel' (/app/.heroku/python/lib/python3.10/site-packages/discord/channel.py)
2022-04-15T05:10:52.949575+00:00 heroku[worker.1]: Process exited with status 1
2022-04-15T05:10:53.184475+00:00 heroku[worker.1]: State changed from up to crashed
2022-04-15T06:01:19.686916+00:00 heroku[worker.1]: State changed from crashed to starting
2022-04-15T06:01:23.574488+00:00 heroku[worker.1]: Starting process with command `python3 bot.py`
2022-04-15T06:01:24.141886+00:00 heroku[worker.1]: State changed from starting to up
2022-04-15T06:01:25.439092+00:00 heroku[worker.1]: State changed from up to crashed
2022-04-15T06:01:25.319879+00:00 heroku[worker.1]: Process exited with status 1
2022-04-15T06:01:25.157617+00:00 app[worker.1]: Traceback (most recent call last):
2022-04-15T06:01:25.157650+00:00 app[worker.1]: File "/app/bot.py", line 1, in <module>
2022-04-15T06:01:25.157743+00:00 app[worker.1]: import discord
2022-04-15T06:01:25.157748+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/__init__.py", line 25, in <module>
2022-04-15T06:01:25.157813+00:00 app[worker.1]: from .client import Client
2022-04-15T06:01:25.157822+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/client.py", line 53, in <module>
2022-04-15T06:01:25.157898+00:00 app[worker.1]: from .webhook import Webhook
2022-04-15T06:01:25.157900+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/webhook/__init__.py", line 12, in <module>
2022-04-15T06:01:25.157953+00:00 app[worker.1]: from .async_ import *
2022-04-15T06:01:25.157961+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord/webhook/async_.py", line 52, in <module>
2022-04-15T06:01:25.158026+00:00 app[worker.1]: from ..channel import PartialMessageable
2022-04-15T06:01:25.158049+00:00 app[worker.1]: ImportError: cannot import name 'PartialMessageable' from 'discord.channel' (/app/.heroku/python/lib/python3.10/site-packages/discord/channel.py)
My code is too long to put here but when I run it locally it works anyway, but if any specific code is needed I can reply with it.
Any help is appreciated, thanks!

Fixed by updating to discord.py v2.0.0a because for some reason when i installed it, i was on v1.7
if anyone needs the import code:
python3 -m pip install -U git+https://github.com/Rapptz/discord.py

Related

Airflow initdb fails due to SyntaxError on importing AsyncRetrying

I am new to Airflow. I install it by pip install apache-airflow. When I run command airflow initdb in terminal then I am getting the error below. Where did I go wrong during install, and how can I fix this issue?
aamir#aamir-Inspiron-3542:~$ airflow initdb
[2019-03-30 18:32:27,309] {__init__.py:51} INFO - Using executor SequentialExecutor
DB: sqlite:////home/aamir/airflow/airflow.db
[2019-03-30 18:32:31,790] {db.py:338} INFO - Creating tables
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [airflow.models.DagBag] Failed to import: /home/aamir/anaconda3/lib/python3.7/site-packages/airflow/example_dags/example_http_operator.py
Traceback (most recent call last):
File "/home/aamir/anaconda3/lib/python3.7/site-packages/airflow/models.py", line 374, in process_file
m = imp.load_source(mod_name, filepath)
File "/home/aamir/anaconda3/lib/python3.7/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 696, in _load
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/aamir/anaconda3/lib/python3.7/site-packages/airflow/example_dags/example_http_operator.py", line 27, in <module>
from airflow.operators.http_operator import SimpleHttpOperator
File "/home/aamir/anaconda3/lib/python3.7/site-packages/airflow/operators/http_operator.py", line 21, in <module>
from airflow.hooks.http_hook import HttpHook
File "/home/aamir/anaconda3/lib/python3.7/site-packages/airflow/hooks/http_hook.py", line 23, in <module>
import tenacity
File "/home/aamir/anaconda3/lib/python3.7/site-packages/tenacity/__init__.py", line 352
from tenacity.async import AsyncRetrying
^
SyntaxError: invalid syntax
Done.
In Python 3.7, async is a reserved keyword, which means it cannot be used in module and variable names. This was valid in prior Python versions, but starting from 3.7, a SyntaxError is raised.
In your case, Airflow comes pre-installed with example DAGs, which were parsed when you ran airflow initdb. Some of those DAGs make use of the SimpleHttpOperator which depends on http_hook.py. That hook furthermore depends on the tenacity library, which tries to import an async module as part of initialization:
from tenacity.async import AsyncRetrying
To fix this, wait for/install Airflow v1.10.3 which updates Tenacity (see AIRFLOW-2876). Alternatively, you can downgrade your Python version. You can see that the import fails using 3.7.3:
$ docker run --rm -it python:3.7
Python 3.7.3 (default, Mar 27 2019, 23:40:30)
>>> from tenacity.async import AsyncRetrying
File "<stdin>", line 1
from tenacity.async import AsyncRetrying
^
SyntaxError: invalid syntax
But it works fine in version 3.6.8:
$ docker run --rm -it python:3.6
Python 3.6.8 (default, Feb 6 2019, 12:07:20)
>>> from tenacity.async import AsyncRetrying
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tenacity'

Discord.py rewrite 'Context' object has no attribute 'send'

Last month I hosted a Discord.py (async version) bot on heroku and it worked perfect, this month I updated my bot from async to rewrite and it doesn't really work.
On my requirements.txt file I have put the git+https://github.com/Rapptz/discord.py#rewrite#egg=discord.py[voice] but it doesn't work.
I always get this error:
2019-01-25T08:30:23.592293+00:00 app[worker.1]: Traceback (most recent call last):
2019-01-25T08:30:23.592356+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 846, in process_commands
2019-01-25T08:30:23.592358+00:00 app[worker.1]: yield from command.invoke(ctx)
2019-01-25T08:30:23.592363+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 374, in invoke
2019-01-25T08:30:23.592365+00:00 app[worker.1]: yield from injected(*ctx.args, **ctx.kwargs)
2019-01-25T08:30:23.592395+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 54, in wrapped
2019-01-25T08:30:23.592397+00:00 app[worker.1]: raise CommandInvokeError(e) from e
2019-01-25T08:30:23.592435+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'send'
Script:
print("Loading Script")
print("Loading Libs")
import discord
import random
from discord.ext import commands
print("Loading Bot")
bot = commands.Bot(command_prefix='!')
#bot.event
async def on_ready():
print("Online!")
#bot.command()
async def rps(ctx):
rpsa = ["Rock", "Paper", "Scissors"]
rpsr = random.choice(rpsa)
await ctx.send(rpsr)
bot.run(Token)
Are you sure you have the right version installed? Just having it in your requirements file doesn't guarantee that you are using the right one. Check what you have installed with pip freeze and then uninstall if necessary the old async version.
That type of error only occurs when you have the async version of discord.py installed and are using rewrite features
Double check what your requirements.txt file is called (you've named it requirement.txt in the question) and check that it doesn't still contain discord==0.0.2 or
discord.py==0.16.12

Heroku: no module named flask though it is in requirements.txt

Can anyone help with this error on Heroku?
2015-01-12T22:26:00.575669+00:00 heroku[web.1]: Starting process with command `python hangman.py`
2015-01-12T22:26:01.066240+00:00 app[web.1]: Traceback (most recent call last):
2015-01-12T22:26:01.066256+00:00 app[web.1]: File "hangman.py", line 3, in <module>
2015-01-12T22:26:01.066262+00:00 app[web.1]: from flask import (
2015-01-12T22:26:01.066268+00:00 app[web.1]: ImportError: No module named flask
2015-01-12T22:26:01.742444+00:00 heroku[web.1]: Process exited with status 1
2015-01-12T22:26:01.751614+00:00 heroku[web.1]: State changed from starting to crashed
My git repo is here: https://github.com/PJBentham/Hangman
I believe I have done everything correct as far as set up is concerned but I'm still getting the above error and can't figure out why?
You have to show the last or pull traceback to debug further ...! You git repo working perfectly fine.
From your traceback snippet flask is not there. Check if your app environ having flask or not using heroku run pip freeze

Maximum clients reached on Heroku and Redistogo Nano

I am using celerybeat on Heroku with RedisToGo Nano addon
There is one web dyno and one worker dyno
The celerybeat worker is set to perform a task every minute.
The problem is: Whenever I deploy a new commit, dynos restart, and I get this error
2014-02-27T13:19:31.552352+00:00 app[worker.1]: Traceback (most recent call last):
2014-02-27T13:19:31.552352+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 389, in start
2014-02-27T13:19:31.552352+00:00 app[worker.1]: self.reset_connection()
2014-02-27T13:19:31.552352+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 727, in reset_connection
2014-02-27T13:19:31.552352+00:00 app[worker.1]: self.connection = self._open_connection()
2014-02-27T13:19:31.552352+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/celery/worker/consumer.py", line 792, in _open_connection
2014-02-27T13:19:31.552352+00:00 app[worker.1]: callback=self.maybe_shutdown)
2014-02-27T13:18:23.864287+00:00 app[worker.1]: self.on_connect()
2014-02-27T13:18:23.864287+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/redis/connection.py", line 263, in on_connect
2014-02-27T13:18:23.864287+00:00 app[worker.1]: if nativestr(self.read_response()) != 'OK':
2014-02-27T13:18:23.864287+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/redis/connection.py", line 314, in read_response
2014-02-27T13:18:23.864287+00:00 app[worker.1]: raise response
2014-02-27T13:18:23.864287+00:00 app[worker.1]: ResponseError: max number of clients reached
2014-02-27T13:19:31.552352+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 272, in ensure_connection
2014-02-27T13:19:31.552352+00:00 app[worker.1]: interval_start, interval_step, interval_max, callback)
2014-02-27T13:19:31.552591+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/utils/__init__.py", line 218, in retry_over_time
2014-02-27T13:19:31.552591+00:00 app[worker.1]: return fun(*args, **kwargs)
2014-02-27T13:19:31.552591+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 162, in connect
2014-02-27T13:19:31.552591+00:00 app[worker.1]: return self.connection
2014-02-27T13:19:31.552591+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 617, in connection
2014-02-27T13:18:23.870811+00:00 app[worker.1]: [2014-02-27 13:18:23,870: ERROR/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...
and those logs go on endlessly. till I stop both dynos and restart them.
It has become a problem because it happens almost every time a new commit is deployed.
Any ideas why this is happening and how to solve this?
The nano redistogo plan caps concurrent redis connections at 10.
The number of redis connects used will vary based on your front-end and celery worker settings. It sounds like you are using >= 5 redis connections for your production stack.
When you deploy new code, Heroku spins up an entirely new stack. This means you are using >= 10 redis connections at the time of deploy.
There are two ways to fix this:
Increase the maximum number of redistogo connections allowed, by upgrading to a larger plan ($$$)
Decrease the number of used connections for your stack (decrease celery concurrency or redis connections used by your web worker)
This is a simple matter of resource exhaustion. I would just pay for a larger RedisToGo plan.

Ubuntu 10.04 - Python multiprocessing - 'module' object has no attribute 'local' error

The following code is from the python 2.6 manual.
from multiprocessing import Process
import os
def info(title):
print(title)
print('module name:', 'me')
print('parent process:', os.getppid())
print('process id:', os.getpid())
def f(name):
info('function f')
print('hello', name)
if __name__ == '__main__':
info('main line')
p = Process(target=f, args=('bob',))
p.start()
p.join()
This creates the following stack traces:
Traceback (most recent call last):
File "threading.py", line 1, in <module>
from multiprocessing import Process
File "/usr/lib/python2.6/multiprocessing/__init__.py", line 64, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/usr/lib/python2.6/multiprocessing/util.py", line 287, in <module>
class ForkAwareLocal(threading.local):
AttributeError: 'module' object has no attribute 'local'
Exception AttributeError: '_shutdown' in <module 'threading' from '/home/v0idnull/tmp/pythreads/threading.pyc'> ignored
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/multiprocessing/util.py", line 258, in _exit_function
info('process shutting down')
TypeError: 'NoneType' object is not callable
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/multiprocessing/util.py", line 258, in _exit_function
info('process shutting down')
TypeError: 'NoneType' object is not callable
I'm completely clueless as to WHY this is happening, and google has given me very little to work with.
that code runs fine on my machine:
Ubuntu 10.10, Python 2.6.6 64-bit.
but your error is actually because you have a file named 'threading.py' that you are running this code from (see the stack-trace details). this is causing a namespace mismatch, since the multiprocessing module needs the 'real' threading module. try renaming your file to something other than 'threading.py' and running it again.
also... the example you posted is not from the Python 2.6 docs... it is from the Python 3.x docs. make sure you are reading the docs for the version that matches what you are running.

Resources