pytr-org / pytr

Use TradeRepublic in terminal and mass download all documents
https://pypi.org/project/pytr/
MIT License
421 stars 74 forks source link

Stuck at 'connecting to websocket' #13

Closed GordonMohrin closed 2 years ago

GordonMohrin commented 2 years ago

Discussed in https://github.com/marzzzello/pytr/discussions/12

Originally posted by **GordonMohrin** November 25, 2021 I downloaded my files correctly on 08.11.2021. Now i wanted to update them but the program is stuck without a timeout. I recreated my credentials file. I am on Version 0.0.9. Using git bash on windows. ```admin@DESKTOP-69OHS5E MINGW64 /e/code/pytr2/pytr (master) $ pip install --upgrade pytr Requirement already satisfied: pytr in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (0.0.8) Collecting pytr Downloading pytr-0.0.9-py3-none-any.whl (21 kB) Requirement already satisfied: pygments in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from pytr) (2.10.0) Requirement already satisfied: websockets in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from pytr) (10.0) Requirement already satisfied: coloredlogs in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from pytr) (15.0.1) Requirement already satisfied: requests-futures in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from pytr) (1.0.0) Requirement already satisfied: ecdsa in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from pytr) (0.17.0) Requirement already satisfied: shtab in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from pytr) (1.4.2) Requirement already satisfied: humanfriendly>=9.1 in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from coloredlogs->pytr) (10.0) Requirement already satisfied: pyreadline3 in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from humanfriendly>=9.1->coloredlogs->pytr) (3.3) Requirement already satisfied: six>=1.9.0 in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from ecdsa->pytr) (1.16.0) Requirement already satisfied: requests>=1.2.0 in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from requests-futures->pytr) (2.26.0) Requirement already satisfied: idna<4,>=2.5 in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from requests>=1.2.0->requests-futures->pytr) (3.3) Requirement already satisfied: certifi>=2017.4.17 in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from requests>=1.2.0->requests-futures->pytr) (2021.10.8) Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from requests>=1.2.0->requests-futures->pytr) (1.26.7) Requirement already satisfied: charset-normalizer~=2.0.0 in c:\users\admin\appdata\local\programs\python\python39\lib\site-packages (from requests>=1.2.0->requests-futures->pytr) (2.0.7) Installing collected packages: pytr Attempting uninstall: pytr Found existing installation: pytr 0.0.8 Uninstalling pytr-0.0.8: Successfully uninstalled pytr-0.0.8 Successfully installed pytr-0.0.9 WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available. You should consider upgrading via the 'c:\users\admin\appdata\local\programs\python\python39\python.exe -m pip install --upgrade pip' command. admin@DESKTOP-69OHS5E MINGW64 /e/code/pytr2/pytr (master) $ pytr dl_docs e:/trdocs 13:43:17 Found credentials file 13:43:17 Phone: +49XXXXXX, PIN: XXXX 13:43:17 Web session resumed 13:43:17 Logged in 13:43:17 Awaiting #1 timeline 13:43:17 Connecting to websocket ... admin@DESKTOP-69OHS5E MINGW64 /e/code/pytr2/pytr (master) $ pytr portfolio 13:58:17 Found credentials file 13:43:17 Phone: +49XXXXXX, PIN: XXXX 13:58:17 Web session resumed 13:58:17 Logged in 13:58:17 Connecting to websocket ... ``` The exception after leaving it running for an hour: ``` Traceback (most recent call last): File "c:\users\admin\appdata\local\programs\python\python39\lib\asyncio\windows_events.py", line 457, in finish_recv return ov.getresult() OSError: [WinError 64] The specified network name is no longer available During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\websockets\legacy\protocol.py", line 944, in transfer_data message = await self.read_message() File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\websockets\legacy\protocol.py", line 1013, in read_message frame = await self.read_data_frame(max_size=self.max_size) File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\websockets\legacy\protocol.py", line 1089, in read_data_frame frame = await self.read_frame(max_size) File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\websockets\legacy\protocol.py", line 1144, in read_frame frame = await Frame.read( File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\websockets\legacy\framing.py", line 70, in read data = await reader(2) File "c:\users\admin\appdata\local\programs\python\python39\lib\asyncio\streams.py", line 723, in readexactly await self._wait_for_data('readexactly') File "c:\users\admin\appdata\local\programs\python\python39\lib\asyncio\streams.py", line 517, in _wait_for_data await self._waiter File "c:\users\admin\appdata\local\programs\python\python39\lib\asyncio\proactor_events.py", line 280, in _loop_reading data = fut.result() File "c:\users\admin\appdata\local\programs\python\python39\lib\asyncio\windows_events.py", line 812, in _poll value = callback(transferred, key, ov) File "c:\users\admin\appdata\local\programs\python\python39\lib\asyncio\windows_events.py", line 461, in finish_recv raise ConnectionResetError(*exc.args) ConnectionResetError: [WinError 64] The specified network name is no longer available The above exception was the direct cause of the following exception: Traceback (most recent call last): File "c:\users\admin\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "c:\users\admin\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\admin\AppData\Local\Programs\Python\Python39\Scripts\pytr.exe\__main__.py", line 7, in File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\pytr\main.py", line 161, in main Portfolio(login(web=weblogin)).get() File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\pytr\portfolio.py", line 73, in get asyncio.get_event_loop().run_until_complete(self.portfolio_loop()) File "c:\users\admin\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 642, in run_until_complete return future.result() File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\pytr\portfolio.py", line 11, in portfolio_loop await self.tr.portfolio() File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\pytr\api.py", line 380, in portfolio return await self.subscribe({'type': 'portfolio'}) File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\pytr\api.py", line 288, in subscribe ws = await self._get_ws() File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\pytr\api.py", line 271, in _get_ws response = await self._ws.recv() File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\websockets\legacy\protocol.py", line 552, in recv await self.ensure_open() File "c:\users\admin\appdata\local\programs\python\python39\lib\site-packages\websockets\legacy\protocol.py", line 920, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedError: no close frame received or sent ```
C0D3D3V commented 2 years ago

Why do you run the program in a Linux subsystem at all? Just open a CMD and execute the commands there. Linux subsystems are known to have many unnecessary bugs, especially MINGW64. I have tested it under Windows with a CMD and it works without problems.

pip install pytr
pytr login
mkdir trdocs
pytr dl_docs trdocs

Result:

C:\Users\Virtual>dir trdocs

 Verzeichnis von C:\Users\Virtual\trdocs

26.11.2021  13:17    <DIR>          .
26.11.2021  13:17    <DIR>          ..
26.11.2021  13:17    <DIR>          Abrechnung
26.11.2021  13:17    <DIR>          Abschlüsse
26.11.2021  13:17    <DIR>          Auftragsbestätigung
26.11.2021  13:17    <DIR>          Ausführungsanzeige
26.11.2021  13:17    <DIR>          Basisinformationen über Wertpapiere
26.11.2021  13:17    <DIR>          Basisinformationsblatt
26.11.2021  13:17    <DIR>          Crypto Verwahrbedingungen
26.11.2021  13:17    <DIR>          Cryptoauszug
26.11.2021  13:17    <DIR>          Datenschutzinformationen
26.11.2021  13:17    <DIR>          Datenschutzinformationen Cryptoverwahrer
26.11.2021  13:17    <DIR>          Ex-Post Kosteninformation
26.11.2021  13:17    <DIR>          Hauptversammlung
26.11.2021  13:17    <DIR>          Hinweise zu den Handelsplätzen
26.11.2021  13:17    <DIR>          Info zur Einlagensicherung
26.11.2021  13:17    <DIR>          Kosteninformation
26.11.2021  13:17    <DIR>          Kundenanschreiben
26.11.2021  13:17    <DIR>          Kundenvereinbarung
26.11.2021  13:17    <DIR>          Löschbestätigung
26.11.2021  13:17    <DIR>          Mistrade Regelungen
26.11.2021  13:17             9.801 other_events.json
26.11.2021  13:17    <DIR>          Preis- und Leistungsverzeichnis
26.11.2021  13:17    <DIR>          Risikohinweise Crypto
26.11.2021  13:17    <DIR>          Sparplan
26.11.2021  13:17    <DIR>          Steuerreport
26.11.2021  13:17    <DIR>          Vorabpauschale
26.11.2021  13:17    <DIR>          Vorvertragliche Informationen
26.11.2021  13:17    <DIR>          Widerrufsbelehrung Cryptoverwahrer
GordonMohrin commented 2 years ago

Same result on CMD and Powershell.

marzzzello commented 2 years ago

I can reproduce on Linux too. Some have this problem others don't. Looks like some dependency is broken in some version

marzzzello commented 2 years ago

The issue is in websockets 10.0. Update pytr to the latest version (0.0.11) with pip install -U pytr. This will make sure websockets>=10.1 is installed