Search code examples
pythonbinance

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?


Solution

  • 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,
    })