how can i use riak in windows with VM? - python

I initialized Riak in a VM and I want use it on Windows in a Python console.
Riak port: 8098, VM host: 192.168.78.128
Windows :
from riak import RiakClient, RiakNode
client = RiakClient(protocol='http', host='192.168.78.128', http_port=8098)
bucket = client.bucket_type('visitors').bucket('hits')
bucket.new("one", data={'value':'one'}, content_type="application/json").store()
output :
Traceback (most recent call last):
File "G:/untitled3/riak_.py", line 13, in <module>
content_type="application/json").store()
File "build\bdist.win32\egg\riak\bucket.py", line 178, in new
File "build\bdist.win32\egg\riak\util.py", line 98, in __get__
File "build\bdist.win32\egg\riak\bucket.py", line 743, in datatype
File "build\bdist.win32\egg\riak\bucket.py", line 675, in get_properties
File "build\bdist.win32\egg\riak\client\transport.py", line 223, in wrapper
File "build\bdist.win32\egg\riak\client\transport.py", line 150, in _with_retries
File "C:\Python27\lib\contextlib.py", line 17, in __enter__
return self.gen.next()
File "build\bdist.win32\egg\riak\transports\pool.py", line 181, in transaction
File "build\bdist.win32\egg\riak\transports\pool.py", line 143, in acquire
File "build\bdist.win32\egg\riak\transports\http\__init__.py", line 155, in create_resource
File "build\bdist.win32\egg\riak\transports\http\transport.py", line 52, in __init__
File "build\bdist.win32\egg\riak\transports\http\connection.py", line 72, in _connect
File "build\bdist.win32\egg\riak\util.py", line 98, in __get__
File "build\bdist.win32\egg\riak\transports\feature_detect.py", line 197, in server_version
File "build\bdist.win32\egg\riak\transports\http\transport.py", line 74, in _server_version
File "build\bdist.win32\egg\riak\transports\http\transport.py", line 65, in stats
File "build\bdist.win32\egg\riak\transports\http\resources.py", line 23, in stats_path
File "build\bdist.win32\egg\riak\util.py", line 98, in __get__
File "build\bdist.win32\egg\riak\transports\http\resources.py", line 222, in riak_kv_wm_stats
File "build\bdist.win32\egg\riak\util.py", line 98, in __get__
File "build\bdist.win32\egg\riak\transports\http\resources.py", line 258, in resources
File "build\bdist.win32\egg\riak\transports\http\transport.py", line 95, in get_resources
File "build\bdist.win32\egg\riak\transports\http\connection.py", line 33, in _request
File "C:\Python27\lib\httplib.py", line 1001, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1035, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 997, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 850, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 812, in send
self.connect()
File "build\bdist.win32\egg\riak\transports\http\__init__.py", line 42, in connect
File "C:\Python27\lib\httplib.py", line 793, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10060] A connection attempt failed because the
connected party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond

Related

Boto3 timeout troubleshooting

I am trying to troubleshoot a situation.
I am initiating a Boto3 client like this:
s3_client = boto3.client('s3')
Then I am iterating over a number of files and uploading them using:
s3_client.upload_file()
My problem is that every now and then I see it pausing for 60 seconds and then continuing normally.
I've tried reducing the timeout value and the error I seem to be getting is:
botocore.exceptions.ConnectTimeoutError
or
urllib3.exceptions.ConnectTimeoutError
If I leave it at 60, eventually it succeeds and I don't get any errors.
My question is, this error means that when executing upload_file, it tried to send a put request to the server and the server didn't respond to that request?
When initiating the client, is any connection established that could be lost or that's simply only storing the credentials and it's irrelevant to this issue?
Many thanks.
Update: Adding more detailed logs:
CRITICAL Connect timeout
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 169, in _new_conn
conn = connection.create_connection(
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 96, in create_connection
raise err
File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 86, in create_connection
sock.connect(sa)
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.10/site-packages/botocore/httpsession.py", line 439, in send
urllib_response = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 507, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 719, in reraise
raise value
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 1012, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 353, in connect
conn = self._new_conn()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 174, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError
During handling of the above exception, another exception occurred:
File "/home/user/.local/lib/python3.10/site-packages/boto3/s3/inject.py", line 143, in upload_file
return transfer.upload_file(
File "/home/user/.local/lib/python3.10/site-packages/boto3/s3/transfer.py", line 288, in upload_file
future.result()
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/futures.py", line 103, in result
return self._coordinator.result()
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/futures.py", line 266, in result
raise self._exception
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/tasks.py", line 139, in __call__
return self._execute_main(kwargs)
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/tasks.py", line 162, in _execute_main
return_value = self._main(**kwargs)
File "/home/user/.local/lib/python3.10/site-packages/s3transfer/upload.py", line 758, in _main
client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
File "/home/user/.local/lib/python3.10/site-packages/botocore/client.py", line 415, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/user/.local/lib/python3.10/site-packages/botocore/client.py", line 731, in _make_api_call
http, parsed_response = self._make_request(
File "/home/user/.local/lib/python3.10/site-packages/botocore/client.py", line 751, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 107, in make_request
return self._send_request(request_dict, operation_model)
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 183, in _send_request
while self._needs_retry(attempts, operation_model, request_dict,
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 305, in _needs_retry
responses = self._event_emitter.emit(
File "/home/user/.local/lib/python3.10/site-packages/botocore/hooks.py", line 358, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "/home/user/.local/lib/python3.10/site-packages/botocore/hooks.py", line 229, in emit
return self._emit(event_name, kwargs)
File "/home/user/.local/lib/python3.10/site-packages/botocore/hooks.py", line 212, in _emit
response = handler(**kwargs)
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 194, in __call__
if self._checker(**checker_kwargs):
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 267, in __call__
should_retry = self._should_retry(attempt_number, response,
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 294, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 333, in __call__
checker_response = checker(attempt_number, response,
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 233, in __call__
return self._check_caught_exception(
File "/home/user/.local/lib/python3.10/site-packages/botocore/retryhandler.py", line 376, in _check_caught_exception
raise caught_exception
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 249, in _do_get_response
http_response = self._send(request)
File "/home/user/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 321, in _send
return self.http_session.send(request)
File "/home/user/.local/lib/python3.10/site-packages/botocore/httpsession.py", line 472, in send
raise ConnectTimeoutError(endpoint_url=request.url, error=e)
The default boto3 retry mode (Legacy) doesn't properly handle a number of errors/exceptions, including RequestThrottled, PriorRequestNotComplete, ConnectionError and BandwidthLimitExceeded. It can manifest as very intermittent problems with long delays and repeated connection failures. You'll likely be better off using the Standard retry mode instead, which also has an exponential backoff.
import boto3
from botocore.client import Config as BotoConfig
TIMEOUT = 3
config = BotoConfig(connect_timeout=TIMEOUT, retries={"mode": "standard"})
client = boto3.client("s3", config=config)

PermissionError: [Errno 13] Permission denied with Binance API (python)

I'm running trading bots written in python in VS Code on mac, trading at binance exchange.
Unfortunately I get sporadic errors when the bot is placing orders, respectively connect via websocket. I really can't explain what's going on because the bots are running well for one or two days and then suddenly this error is disrupting the strategy, because it causes that orders are not cancelled anymore when they should leading to unsecured trades (without stop).
Message: 'Starting new HTTPS connection (%d): %s:%s'
Arguments: (1, 'fapi.binance.com', 443)
--- Logging error ---
Traceback (most recent call last):
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1038, in emit
self.flush()
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1018, in flush
self.stream.flush()
PermissionError: [Errno 13] Permission denied
Call stack:
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/engine_LinReg.py", line 102, in execute
execution_short_ETH.main()
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/execution_short_ETH.py", line 22, in main
response_tradelist = sr.send_signed_request('GET', '/fapi/v1/userTrades', params)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/send_requests_ETH.py", line 49, in send_signed_request
response = dispatch_request(http_method)(**params)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 393, in _make_request
httplib_response.length)
Message: '%s://%s:%s "%s %s %s" %s %s'
Arguments: ('https', 'fapi.binance.com', 443, 'GET', '/fapi/v1/userTrades?timestamp=1630094893528&signature=456f8b3cf34a36ad257114d4e8a7ca31d43c27ddb8ad8296bc7e3d3d416f9145', 'HTTP/1.1', 200, None)
--- Logging error ---
Traceback (most recent call last):
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1038, in emit
self.flush()
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1018, in flush
self.stream.flush()
PermissionError: [Errno 13] Permission denied
Call stack:
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/engine_LinReg.py", line 102, in execute
execution_short_ETH.main()
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/execution_short_ETH.py", line 34, in main
#response = sr.send_public_request('/fapi/v1/ticker/24hr?symbol='+symbol)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/send_requests_ETH.py", line 59, in send_public_request
response = dispatch_request('GET')(url=url)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 588, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 248, in _get_conn
return conn or self._new_conn()
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 813, in _new_conn
self.num_connections, self.host, self.port or "443")
Message: 'Starting new HTTPS connection (%d): %s:%s'
Arguments: (1, 'fapi.binance.com', 443)
--- Logging error ---
Traceback (most recent call last):
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1038, in emit
self.flush()
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1018, in flush
self.stream.flush()
PermissionError: [Errno 13] Permission denied
Call stack:
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/engine_LinReg.py", line 102, in execute
execution_short_ETH.main()
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/execution_short_ETH.py", line 34, in main
#response = sr.send_public_request('/fapi/v1/ticker/24hr?symbol='+symbol)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/send_requests_ETH.py", line 59, in send_public_request
response = dispatch_request('GET')(url=url)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 393, in _make_request
httplib_response.length)
Message: '%s://%s:%s "%s %s %s" %s %s'
Arguments: ('https', 'fapi.binance.com', 443, 'POST', '/fapi/v1/order?symbol=ETHUSDT&side=SELL&type=MARKET&quantity=0.01&newOrderRespType=RESULT&timestamp=1630094894451&signature=67252a93834cedde133ad0fa62683126a9ca583147fffcf2cefbdff071fa4ce3', 'HTTP/1.1', 200, None)
--- Logging error ---
Traceback (most recent call last):
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1038, in emit
self.flush()
File "/Users/username/anaconda3/lib/python3.7/logging/__init__.py", line 1018, in flush
self.stream.flush()
PermissionError: [Errno 13] Permission denied
Call stack:
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 885, in _bootstrap
self._bootstrap_inner()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/username/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/engine_LinReg.py", line 102, in execute
execution_short_ETH.main()
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/execution_short_ETH.py", line 58, in main
TP = int(entryPrice-settings_ETH.TP)
File "/Users/username/Workfiles/python/binance/vs_binance_algo/ETH_LinReg/send_requests_ETH.py", line 49, in send_signed_request
response = dispatch_request(http_method)(**params)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/username/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 588, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 248, in _get_conn
return conn or self._new_conn()
File "/Users/username/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 813, in _new_conn
self.num_connections, self.host, self.port or "443")
...and so on...
I can't find anything in the dev.binance forum in this regard (and they are anyway not very helpful).
What does this error mean?
My intuition is an imported module try to create a log file with logging module and raise a PermissionError.
Try to disable logging:
import logging.config
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': True,
})

OSError when using selenium in multiple scripts simultaneously

I am running several Python scripts at the same time on Windows, each using Selenium to get data from the web. If I run only one of them individually, all works well. But when run together, I keep getting the following error:
OSError: [WinError 10048] Only one usage of each socket address
(protocol/network address/port) is normally permitted
and it always comes at a line that uses the find_element_by_tag_name function of Selenium. Here is an example of a full traceback. It's a bit long, but it shows that it is occuring when trying to run the socket.connect method. Any advice on why this is occuring and how I can achieve my goal of simultaneously running Python scripts that use Selenium?
Traceback (most recent call last):
File "<ipython-input-1-ba99a1a73a3a>", line 1, in <module>
runfile('D:/testFolder/test.py', wdir='D:/testFolder')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/testFolder/test.py", line 40, in <module>
files = [file.find_element_by_tag_name('a') for file in files]
File "D:/testFolder/test.py", line 40, in <listcomp>
files = [file.find_element_by_tag_name('a') for file in files]
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 230, in find_element_by_tag_name
return self.find_element(by=By.TAG_NAME, value=name)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 516, in find_element
{"using": by, "value": value})['value']
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 499, in _execute
return self._parent.execute(command, params)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 295, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 464, in execute
return self._request(command_info[0], url, body=data)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 487, in _request
self._conn.request(method, parsed_url.path, body, headers)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 964, in send
self.connect()
File "C:\ProgramData\Anaconda3\lib\http\client.py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\ProgramData\Anaconda3\lib\socket.py", line 722, in create_connection
raise err
File "C:\ProgramData\Anaconda3\lib\socket.py", line 713, in create_connection
sock.connect(sa)
OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

Mongodb crashes when the same collection in accessed by two different python script using pymongo

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.

Unexpected pika.exceptions.ConnectionClosed exception

I randomly get the following errors (i.e most of the times the scripts work fine)
File ".../backend/case_status_consumer.py", line 28, in <module>
channel.start_consuming()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 955, in start_consuming
self.connection.process_data_events()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 240, in process_data_events
if self._handle_read():
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 348, in _handle_read
super(BlockingConnection, self)._handle_read()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 351, in _handle_read
self._on_data_available(data)
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1285, in _on_data_available
self._process_frame(frame_value)
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1365, in _process_frame
self._deliver_frame_to_channel(frame_value)
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 976, in _deliver_frame_to_channel
return self._channels[value.channel_number]._handle_content_frame(value)
File "/usr/local/lib/python2.7/dist-packages/pika/channel.py", line 792, in _handle_content_frame
self._on_deliver(*response)
File "/usr/local/lib/python2.7/dist-packages/pika/channel.py", line 886, in _on_deliver
body)
File ".../backend/case_status_consumer.py", line 14, in consume_case_status
case_num['case_year'])
File ".../backend/src/fetcher/case_update.py", line 132, in case_update
properties=pika.BasicProperties(delivery_mode=2))
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 572, in basic_publish
(properties, body), False)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 1159, in _send_method
self.connection.send_method(self.channel_number, method_frame, content)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 274, in send_method
self._send_method(channel_number, method_frame, content)
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1503, in _send_method
self._send_frame(frame.Method(channel_number, method_frame))
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 417, in _send_frame
super(BlockingConnection, self)._send_frame(frame_value)
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1490, in _send_frame
self._flush_outbound()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 377, in _flush_outbound
if self._handle_write():
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 365, in _handle_write
return self._handle_error(error)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 302, in _handle_error
self._handle_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 248, in _handle_disconnect
self._adapter_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 318, in _adapter_disconnect
self._check_state_on_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 371, in _check_state_on_disconnect
raise exceptions.ConnectionClosed()
pika.exceptions.ConnectionClosed
And I get a similar error while producing too.
File ".../backend/check_for_orders.py", line 115, in <module>
dated=order_dated, ors_fetch=False)
File ".../backend/src/fetcher/case_update.py", line 132, in case_update
properties=pika.BasicProperties(delivery_mode=2))
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 572, in basic_publish
(properties, body), False)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 1159, in _send_method
self.connection.send_method(self.channel_number, method_frame, content)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 274, in send_method
self._send_method(channel_number, method_frame, content)
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1503, in _send_method
self._send_frame(frame.Method(channel_number, method_frame))
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 417, in _send_frame
super(BlockingConnection, self)._send_frame(frame_value)
File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1490, in _send_frame
self._flush_outbound()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 377, in _flush_outbound
if self._handle_write():
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 365, in _handle_write
return self._handle_error(error)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 302, in _handle_error
self._handle_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 248, in _handle_disconnect
self._adapter_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 318, in _adapter_disconnect
self._check_state_on_disconnect()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 371, in _check_state_on_disconnect
raise exceptions.ConnectionClosed()
pika.exceptions.ConnectionClosed
My connection is set to:
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', heartbeat_interval=0))
I have even tried setting the heartbeat interval to a longer time (like 60 and 90), but I still get these errors.
I cannot post the full code but what my scripts are doing is, using 'requests' to fetch a page (with timeout as 50 seconds and maximum 4 retries)
This issue is fixed in pika 0.10.0

Categories

Resources