pytr-org / pytr

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

Not able to download files and getting the following error in socket creation #142

Open malinazakat opened 1 week ago

malinazakat commented 1 week ago

Description of the bug I am getting the following error in multiple commands.

To Reproduce Steps to reproduce the behavior:

  1. Ran the command pytr -v debug dl_docs 'C:\Users\XXX\Downloads'
  2. Followed the instructions

Expected behavior Files to be downloaded.

Error log 2024-11-10 16:56:38+0100 main DEBUG logging is set to debug 2024-11-10 16:56:38+0100 account INFO Credentials file not found Please enter your TradeRepublic phone number in the format +4912345678: xxx Please enter your TradeRepublic pin: Pin (Input is hidden): xxx Save credentials? Type "y" to save credentials:

2024-11-10 16:56:41+0100 account INFO Credentials not saved Enter the code you received to your mobile app as a notification. Enter nothing if you want to receive the (same) code as SMS. (Countdown: 31) Code: xxx 2024-11-10 16:56:46+0100 account INFO Logged in 2024-11-10 16:56:46+0100 dl INFO Created history file 2024-11-10 16:56:46+0100 timeline INFO Subscribing to #1 timeline transactions 2024-11-10 16:56:46+0100 api INFO Connecting to websocket ...

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "c:\users\xxx\.local\bin\pytr.exe\__main__.py", line 7, in <module>
  File "C:\Users\xxx\pipx\venvs\pytr\Lib\site-packages\pytr\main.py", line 266, in main
    asyncio.get_event_loop().run_until_complete(dl.dl_loop())
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\xxx\pipx\venvs\pytr\Lib\site-packages\pytr\dl.py", line 68, in dl_loop
    await self.tl.get_next_timeline_transactions()
  File "C:\Users\xxx\pipx\venvs\pytr\Lib\site-packages\pytr\timeline.py", line 30, in get_next_timeline_transactions
    await self.tr.timeline_transactions()
  File "C:\Users\xxx\pipx\venvs\pytr\Lib\site-packages\pytr\api.py", line 506, in timeline_transactions
    return await self.subscribe({"type": "timelineTransactions", "after": after})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\pipx\venvs\pytr\Lib\site-packages\pytr\api.py", line 322, in subscribe
    ws = await self._get_ws()
         ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\pipx\venvs\pytr\Lib\site-packages\pytr\api.py", line 301, in _get_ws
    self._ws = await websockets.connect(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\pipx\venvs\pytr\Lib\site-packages\websockets\asyncio\client.py", line 441, in __await_impl__
    self.connection = await self.create_connection()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\pipx\venvs\pytr\Lib\site-packages\websockets\asyncio\client.py", line 367, in create_connection
    _, connection = await loop.create_connection(factory, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers'

Environment

ralfescher commented 1 week ago

I had the same error running this command on my Mac with Python 3.12.4. Could solve this issue by running the program in a virtual python 3.9 environment (see #141).

malinazakat commented 1 week ago

Tried with Python 3.13 and now got slightly different error

20:19:36 Logged in
20:19:36 Created history file
20:19:36 Subscribing to #1 timeline transactions
20:19:36 Connecting to websocket ...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "c:\users\ali\.local\bin\pytr.exe\__main__.py", line 7, in <module>
    sys.exit(main())
             ~~~~^^
  File "C:\Users\Ali\pipx\venvs\pytr\Lib\site-packages\pytr\main.py", line 266, in main
    asyncio.get_event_loop().run_until_complete(dl.dl_loop())
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "C:\Users\Ali\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "C:\Users\Ali\pipx\venvs\pytr\Lib\site-packages\pytr\dl.py", line 68, in dl_loop
    await self.tl.get_next_timeline_transactions()
  File "C:\Users\Ali\pipx\venvs\pytr\Lib\site-packages\pytr\timeline.py", line 30, in get_next_timeline_transactions
    await self.tr.timeline_transactions()
  File "C:\Users\Ali\pipx\venvs\pytr\Lib\site-packages\pytr\api.py", line 506, in timeline_transactions
    return await self.subscribe({"type": "timelineTransactions", "after": after})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ali\pipx\venvs\pytr\Lib\site-packages\pytr\api.py", line 322, in subscribe
    ws = await self._get_ws()
         ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ali\pipx\venvs\pytr\Lib\site-packages\pytr\api.py", line 301, in _get_ws
    self._ws = await websockets.connect(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
        "wss://api.traderepublic.com", ssl=ssl_context, extra_headers=extra_headers
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\Ali\pipx\venvs\pytr\Lib\site-packages\websockets\asyncio\client.py", line 441, in __await_impl__
    self.connection = await self.create_connection()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ali\pipx\venvs\pytr\Lib\site-packages\websockets\asyncio\client.py", line 367, in create_connection
    _, connection = await loop.create_connection(factory, **kwargs)
                          ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
TypeError: BaseEventLoop.create_connection() got an unexpected keyword argument 'extra_headers'
malinazakat commented 1 week ago

Did not work for me with Python 3.9.13 either.

ralfescher commented 1 week ago

I asked ChatGPT for help, and it suggested downgrading the WebSockets version: pip install websockets==10.2 Took me also some time to get Python 3.9 running in a virtual environment (venv).

malinazakat commented 1 week ago

Thanks a lot. worked for me too with the downgraded websockets version.

msdn65 commented 1 week ago

same here worked after downgrading websockets

boenhoff commented 1 week ago

Just for others, not sure if that is the best solution but it works for me, didn't work much with python yet:

JAK0721 commented 6 days ago

Just for others, what worked for me under Windows 11 --> open "Eingabeauforderung" (search "cmd")

  1. installed python 3.12
  2. mkdir pytr
  3. cd pytr
  4. python -m venv pytr
  5. pytr\Scripts\activate
  6. pip install pytr
  7. pip install websockets==10.2
  8. pytr dl_docs -n +49xxxxx -p xxxx C:\Users\xxxx\pytr
uabalabadubdub commented 6 days ago

Using it on Ubuntu WSL (Ubuntu 20.04.6 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)). Python 3.13. Same error as this.

Downgrading websockets as suggested here works

pipx inject pytr websockets==10.2 --force

Without reinstallation, just force downgrade of websockets package on the venv