在Debian WSL上打开80端口以设置一个小型数据库



我试图在这个项目中设置一个自动Python交易机器人。我已经将repo克隆到WSL机器(Debian OS)上,并开始执行main.

项目中有一个记录器策略,它返回我成功运行的给定货币对(例如BTC_EUR)的当前价格。

下一步是导入给定时间段的价格数据,并将其保存在本地数据库中以执行分析和回测。但是运行导入策略会返回以下错误消息:

Traceback (most recent call last):
File "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/util/connection.py", line 74, 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 "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
chunked=chunked,
File "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.7/http/client.py", line 1260, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1306, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1255, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1030, in _send_output
self.send(msg)
File "/usr/lib/python3.7/http/client.py", line 970, in send
self.connect()
File "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/connection.py", line 187, in connect
conn = self._new_conn()
File "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/connection.py", line 172, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f3ec7c8eeb8>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/chrisd/.local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/chrisd/.local/lib/python3.7/site-packages/urllib3/util/retry.py", line 446, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /api/datasets (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f3ec7c8eeb8>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./main.py", line 81, in <module>
importer = Importer(exchange, period_start, period_end, interval)
File "/home/chrisd/repos/cryptobot/services/importer.py", line 16, in __init__
'currency': '/api/currencies/'+self.exchange.currency.lower(), 'asset': '/api/currencies/'+self.exchange.asset.lower()})
File "/home/chrisd/repos/cryptobot/api/rest.py", line 91, in create
response = self.post(self.serialize(data))
File "/home/chrisd/repos/cryptobot/api/rest.py", line 72, in post
return self.query(method="post", data=json.dumps(self.serialize(data)), headers=self.build_headers(headers))
File "/home/chrisd/repos/cryptobot/api/rest.py", line 32, in query
response = http_method(self.build_url(self.resource_name, iri), data=data, headers=headers).json()
File "/home/chrisd/.local/lib/python3.7/site-packages/requests/api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "/home/chrisd/.local/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/chrisd/.local/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/chrisd/.local/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/chrisd/.local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /api/datasets (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f3ec7c8eeb8>: Failed to establish a new connection: [Errno 111] Connection refused'))

据我所知,脚本不能建立一个HTTP连接和我的linux机器在端口80上。

以下是我输入ss -lt命令时得到的结果:
State          Recv-Q          Send-Q                   Local Address:Port                   Peer Address:Port

显然这里没有80端口的标志。没有安装防火墙(UFW),在这种情况下,我找不到打开特定端口的linux命令。关于如何在WSL上打开80端口以建立HTTP连接和设置数据库,有什么想法吗?

谢谢你的回答。

如果您使用的是WSL2,这是一个已知的问题。你可以在这里找到解决方法和更多信息:https://github.com/microsoft/WSL/issues/4150

最新更新