Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
malinazakat opened this issue Nov 10, 2024 · 16 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@malinazakat
Copy link

malinazakat commented Nov 10, 2024

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

  • OS: windows
  • pytr version: 0.3.1
  • Python: 3.11
@malinazakat malinazakat added the bug Something isn't working label Nov 10, 2024
@ralfescher
Copy link

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
Copy link
Author

malinazakat commented Nov 10, 2024

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
Copy link
Author

Did not work for me with Python 3.9.13 either.

@ralfescher
Copy link

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
Copy link
Author

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

@msdn65
Copy link

msdn65 commented Nov 11, 2024

same here worked after downgrading websockets

@boenhoff
Copy link

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

  • installing pytr with python 3.9 pipx reinstall pytr --python /opt/homebrew/bin/python3.9
  • downgrade websockets pipx inject pytr websockets==10.2 --force

@JAK0721
Copy link

JAK0721 commented Nov 16, 2024

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
Copy link

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

@sektorenkoppler
Copy link

Same Problem with 3.13.1.

websockets downgrade worked for me on win11

@ovizii
Copy link

ovizii commented Dec 6, 2024

I was using this Dockerfile to build my own local container when I was hit with this error. I read all the tips here and some other related issues on thus project and am still failing. Furthermore, I'd appreciate some pointers.

I went with the advice from this thread to go with python 3.9 and websockets==10.2 and no such luck. What happens is, I get asked the PIN, the connection to TR succeeds, I can see the subscriptions happening and downloading, and it gets to about 5200 /out of 5500 and then hundreds of error messages like this one:

16:28:21 Received error message: '6299 E {"errors":[{"errorCode":"UNKNOWN_ERROR","errorField":null,"errorMessage":"Unknown error","meta":{"source":"PLATFORM"}}]}'
16:28:21 Error response for subscription "{'type': 'timelineDetailV2', 'id': '5de9b8d1-ae18-4dfb-b01d-714d13ea1f6a'}". Re-subscribing...

FROM        python:3.9-alpine

ARG         USER=xyz
ARG         UID=1000
ARG         GID=1000

RUN         python3 -m venv /app &&\
            /app/bin/pip install pytr websockets==10.2 &&\
            addgroup -g ${GID} -S ${USER} &&\
            adduser -u ${UID} -S ${USER} -G ${USER} &&\
            chown -R ${UID}:${GID} /app

WORKDIR     /app/bin

USER        xyz

CMD         ["--help"]

ENTRYPOINT  ["/app/bin/python3", "pytr"]

Just in case you're curious, I override the CMD in the compose file with:

    command:
      - "dl_docs"
      - "/documents"

and /documents is a mounted volume.

@Martl91
Copy link

Martl91 commented Dec 9, 2024

Deleted , Not helpful

@kacnje
Copy link

kacnje commented Jan 11, 2025

I have the same problem (Windows 11, Python 3.13.1).
Can we expect a solution?

@ovizii
Copy link

ovizii commented Jan 13, 2025

You just need to change the directory in line 22 where the folder for such problems will be created. self.problems_folder =r"E:\01_Alle_Infos\08_Aktien\01_Trade_Republic\Aktien_Trade_Republic_Import\Upload_TR\Probleme" # Ordner für problematische Events If someone find a better solution please write me. File is attached timeline.py.txt

When you say change, you mean add? As looking at the original file, I see no such line: https://github.com/pytr-org/pytr/blob/master/pytr/timeline.py

I'm going to give it a try, thanks for sharing your solution. I hope the original maintainer will fix this officially.

@Martl91
Copy link

Martl91 commented Jan 13, 2025

Hi ovizii,

This Solution is Not Helpful it works only one time at another day again not , i will delete it.
you should use the workaround from #148 and change the Lines , this works better Till someone fix it. Search in this Tonic #148 for JustinTrvz his workaround help to Download the documents. But use the original Timeline.py.
I would suggest to update all Pytr files then make a backup of all files what you Downloaded, after that Delete history file and try to Login. In my case he downloaded all files . And.. good luck :-)

@NiklasRosenstein
Copy link
Collaborator

Duplicate of #143

Initially addressed by #160, but #145 implemented support for Websockets 14.

@NiklasRosenstein NiklasRosenstein added the duplicate This issue or pull request already exists label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests