I first followed the tutorial on the heroku site. I did this
pip install rq
then in a worker.py file
import os
import redis
from rq import Worker, Queue, Connection
listen = ['high', 'default', 'low']
redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
conn = redis.from_url(redis_url)
if __name__ == '__main__':
with Connection(conn):
worker = Worker(map(Queue, listen))
worker.work()
and then
python worker.py
and I got the following error
Traceback (most recent call last):
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect
raise err
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 572, in execute_command
connection.send_command(*args)
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect
raise err
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "worker.py", line 15, in <module>
worker.work()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/rq/worker.py", line 423, in work
self.register_birth()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/rq/worker.py", line 242, in register_birth
if self.connection.exists(self.key) and \
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 855, in exists
return self.execute_command('EXISTS', name)
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 578, in execute_command
connection.send_command(*args)
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
I then went to google and found the package index which I also followed which is
>>> import redis
>>> r = redis.StrictRedis(host='localhost', port=6379, db=0)
>>> r.set('foo', 'bar')
hit enter and got the following message
Traceback (most recent call last):
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect
raise err
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 572, in execute_command
connection.send_command(*args)
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect
raise err
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 1072, in set
return self.execute_command('SET', *pieces)
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/client.py", line 578, in execute_command
connection.send_command(*args)
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
I have done no more or less then what these tutorials ask. How can I make this work?
You need to run the redis server. Type redis-server on you console to start the server(Mac OSX).
$redis-server
Remember that the worker needs a broker(redis) in order to communicate with your app.
Related
I use ubuntu 20.04 in AWS.
I have created a python asyio webapp.
I use Nginx.
The Nginx default page could load successfully.
However, after deploying my webapp, error occurs:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/aiomysql/connection.py", line 503, in _connect
await self._request_authentication()
File "/usr/local/lib/python3.8/dist-packages/aiomysql/connection.py", line 796, in _request_authentication
await self._process_auth(plugin_name, auth_packet)
File "/usr/local/lib/python3.8/dist-packages/aiomysql/connection.py", line 819, in _process_auth
await self.sha256_password_auth(auth_packet)
File "/usr/local/lib/python3.8/dist-packages/aiomysql/connection.py", line 970, in sha256_password_auth
pkt = await self._read_packet()
File "/usr/local/lib/python3.8/dist-packages/aiomysql/connection.py", line 593, in _read_packet
packet.check_error()
File "/usr/local/lib/python3.8/dist-packages/pymysql/protocol.py", line 220, in check_error
err.raise_mysql_exception(self._data)
File "/usr/local/lib/python3.8/dist-packages/pymysql/err.py", line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'www'#'localhost' (using password: YES)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 154, in <module>
loop.run_until_complete(init(loop))
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "app.py", line 142, in init
yield from orm.create_pool(loop=loop, **configs.db)
File "/home/ubuntu/srv/awesome/www/orm.py", line 17, in create_pool
__pool = yield from aiomysql.create_pool(
File "/usr/local/lib/python3.8/dist-packages/aiomysql/pool.py", line 29, in _create_pool
await pool._fill_free_pool(False)
File "/usr/local/lib/python3.8/dist-packages/aiomysql/pool.py", line 167, in _fill_free_pool
conn = await connect(echo=self._echo, loop=self._loop,
File "/usr/local/lib/python3.8/dist-packages/aiomysql/connection.py", line 75, in _connect
await conn._connect()
File "/usr/local/lib/python3.8/dist-packages/aiomysql/connection.py", line 521, in _connect
raise OperationalError(2003,
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1'")
How to fix my problem?
I'm following this guide here https://github.com/flaree/Flare-Cogs/tree/master/dankmemer. I got to the import rethinkdb part but I get this error when running the r.connect('localhost', 28015).repl()
command. Been searching yesterday for a fix but couldn't find one.
r.connect('localhost', 28015).repl()
Traceback (most recent call last):
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 349, in __init__
self._socket = socket.create_connection((self.host, self.port), timeout)
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/venv/lib/python3.8/site-packages/rethinkdb/__init__.py", line 93, in connect
return self.make_connection(self.connection_type, *args, **kwargs)
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 830, in make_connection
return conn.reconnect(timeout=timeout)
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 696, in reconnect
return self._instance.connect(timeout)
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 538, in connect
self._socket = SocketWrapper(self, timeout)
File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 437, in __init__
raise ReqlDriverError(
rethinkdb.errors.ReqlDriverError: Could not connect to localhost:28015. Error: [Errno 111] Connection refused```
You need to run rethinkdb first.
Enter your venv, and run tmux. Then run rethinkdb inside your tmux shell. This starts the rethinkdb server, and keeps it running. Close the SSH session, and open another one. Try running your code again.
I have written a script which gets data from a sqlite db to upload into MySQL db. The structure of the code is as below.
def insert_to_mysql(_row):
# get mysql connection by Pymysql
connection = pymysql.connect(..., connect_timeout=31536000)
# insert data
connection.close
def get_data_from_sqlite(_db):
for i in sqlite_generator:
insert_to_mysql(i)
the code works fine. But the connection get's time out without certain pattern with the below trace back very often, despite the connect_timeout in connection object and I am using one object per row. My logic is to create one object for a row so that there will not be timeout issue.
Can anyone help me in understanding what's going wrong here?
Traceback (most recent call last):
File "/home/santhosh/.local/lib/python3.5/site-packages/pymysql/connections.py", line 691, in _read_bytes
data = self._rfile.read(num_bytes)
File "/usr/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "up_data_upload.py", line 85, in <module>
import_data(record)
File "up_data_upload.py", line 43, in import_data
db='up_scrape_data')
File "up_data_upload.py", line 31, in get_mysql_connection
connect_timeout=31536000)
File "/home/santhosh/.local/lib/python3.5/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/home/santhosh/.local/lib/python3.5/site-packages/pymysql/connections.py", line 325, in __init__
self.connect()
File "/home/santhosh/.local/lib/python3.5/site-packages/pymysql/connections.py", line 598, in connect
self._get_server_information()
File "/home/santhosh/.local/lib/python3.5/site-packages/pymysql/connections.py", line 975, in _get_server_information
packet = self._read_packet()
File "/home/santhosh/.local/lib/python3.5/site-packages/pymysql/connections.py", line 657, in _read_packet
packet_header = self._read_bytes(4)
File "/home/santhosh/.local/lib/python3.5/site-packages/pymysql/connections.py", line 699, in _read_bytes
"Lost connection to MySQL server during query (%s)" % (e,))
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query ([Errno 110] Connection timed out)')
Thanks in advance.
Hi i can't start my bot discord
root#boot:~/mdrk/discord.py# python3.5 discordbot.py
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 601, in _create_direct_connection
local_addr=self._local_addr)
File "/usr/local/lib/python3.5/asyncio/base_events.py", line 695, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.5/asyncio/base_events.py", line 682, in create_connection
yield from self.sock_connect(sock, address)
File "/usr/local/lib/python3.5/asyncio/futures.py", line 361, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/local/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
future.result()
File "/usr/local/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/local/lib/python3.5/asyncio/selector_events.py", line 439, in _sock_connect_cb
raise OSError(err, 'Connect call failed %s' % (address,))
OSError: [Errno 113] Connect call failed ('104.16.59.5', 443)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 304, in connect
yield from self._create_connection(req)
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 578, in _create_connection
transport, proto = yield from self._create_direct_connection(req)
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 624, in _create_direct_connection
(req.host, req.port, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 113] Can not connect to discordapp.com:443 [Connect call failed ('104.16.59.5', 443)]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "discordbot.py", line 121, in <module>
client.run('token')
File "/root/mdrk/discord.py/discord/client.py", line 518, in run
self.loop.run_until_complete(self.start(*args, **kwargs))
File "/usr/local/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
return future.result()
File "/usr/local/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/local/lib/python3.5/asyncio/tasks.py", line 241, in _step
result = coro.throw(exc)
File "/root/mdrk/discord.py/discord/client.py", line 489, in start
yield from self.login(*args, **kwargs)
File "/root/mdrk/discord.py/discord/client.py", line 416, in login
yield from getattr(self, '_login_' + str(n))(*args, **kwargs)
File "/root/mdrk/discord.py/discord/client.py", line 346, in _login_1
data = yield from self.http.static_login(token, bot=is_bot)
File "/root/mdrk/discord.py/discord/http.py", line 258, in static_login
data = yield from self.request(Route('GET', '/users/#me'))
File "/root/mdrk/discord.py/discord/http.py", line 137, in request
r = yield from self.session.request(method, url, **kwargs)
File "/usr/local/lib/python3.5/site-packages/aiohttp/client.py", line 555, in __iter__
resp = yield from self._coro
File "/usr/local/lib/python3.5/site-packages/aiohttp/client.py", line 198, in _request
conn = yield from self._connector.connect(req)
File "/usr/local/lib/python3.5/site-packages/aiohttp/connector.py", line 314, in connect
.format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 113] Cannot connect to host discordapp.com:443 ssl:True [Can not connect to discordapp.com:443 [Connect call failed ('104.16.59.5', 443)]]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f21a06dae48>
I need you help
This is an educational open source project with many sub-projects. The one I am studying currently is the 'crawler' project. It requires python 3.4+ and aiohttp 1.2+. My current setup is Windows 10, Python 3.6.1, and aiohttp 2.0.4.
Strangely, my tests do not run and it is related to aiohttp. Can anybody familiar with aiohttp tell me why?
Here is the output I get:
I have two python scripts, currentdataupload.py and productioncount.py on my Ubuntu server. currentdataupload.py uploads dummy current data and productioncount.py accesses that data to do some calculations. The code runs perfectly in other scenarios without disrupting the MongoDB, but when I run both of these codes simultaneously using nohup after a few seconds it exits the mongoDB service and is no longer able to upload or retrieve data. I would like to know if I am doing the entire process the right way or I am messing up somewhere big time.
Error log
Traceback (most recent call last):
File "/python_codes/currentdataupload.py", line 38, in <module>
result = posts.insert_one(post_data)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/collection.py", line 630, in insert_one
bypass_doc_val=bypass_document_validation),
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/collection.py", line 535, in _insert
check_keys, manipulate, write_concern, op_id, bypass_doc_val)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/collection.py", line 516, in _insert_one
check_keys=check_keys)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 244, in command
self._raise_connection_failure(error)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 372, in _raise_connection_failure
raise error
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 239, in command
read_concern)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/network.py", line 96, in command
response = receive_message(sock, 1, request_id)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/network.py", line 123, in receive_message
header = _receive_data_on_socket(sock, 16)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/network.py", line 161, in _receive_data_on_socket
raise AutoReconnect("connection closed")
pymongo.errors.AutoReconnect: connection closed
Traceback (most recent call last):
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 543, in connect
sock = _configured_socket(self.address, self.opts)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 452, in _configured_socket
sock = _create_connection(address, options)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 436, in _create_connection
raise err
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 429, in _create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/python_codes/productioncount.py", line 267, in <module>
result = col2.find_one({"date": date, "machine": machine})
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/collection.py", line 1014, in find_one
for result in cursor.limit(-1):
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/cursor.py", line 1090, in next
if len(self.__data) or self._refresh():
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/cursor.py", line 1012, in _refresh
self.__read_concern))
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/cursor.py", line 850, in __send_message
**kwargs)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/mongo_client.py", line 844, in _send_message_with_response
exhaust)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/mongo_client.py", line 855, in _reset_on_error
return func(*args, **kwargs)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/server.py", line 99, in send_message_with_response
with self.get_socket(all_credentials, exhaust) as sock_info:
File "/root/anaconda3/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/server.py", line 163, in get_socket
with self.pool.get_socket(all_credentials, checkout) as sock_info:
File "/root/anaconda3/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 582, in get_socket
sock_info = self._get_socket_no_auth()
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 628, in _get_socket_no_auth
sock_info = self._check(sock_info)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 682, in _check
return self.connect()
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 555, in connect
_raise_connection_failure(self.address, error)
File "/root/anaconda3/lib/python3.5/site-packages/pymongo/pool.py", line 65, in _raise_connection_failure
raise AutoReconnect(msg)
pymongo.errors.AutoReconnect: localhost:27017: [Errno 111] Connection refused
MongoDB shouldn't crash. Please file a bug report, including the Python script you run and a complete MongoDB logfile, at jira.mongodb.org.