pytr-org / pytr

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

ValueError: Connection Error: failed 29 Segmentation fault after dl_docs #42

Closed parodev93 closed 8 months ago

parodev93 commented 9 months ago

Description of the bug After trying to download documents via dl_docs im getting following error:

Error log $ pytr -v debug dl_docs . 2023-10-02 20:43:21+0200 main DEBUG logging is set to debug 2023-10-02 20:43:21+0200 account INFO Found credentials file 2023-10-02 20:43:21+0200 account INFO Phone: ****, PIN: **** 2023-10-02 20:43:21+0200 account INFO Web session resumed 2023-10-02 20:43:21+0200 account INFO Logged in 2023-10-02 20:43:21+0200 dl INFO Found 419 lines in history file 2023-10-02 20:43:21+0200 utils INFO Awaiting timeline 2023-10-02 20:43:21+0200 api INFO Connecting to websocket ... Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python311\Scripts\pytr.exe__main__.py", line 7, in File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytr\main.py", line 206, in main asyncio.get_event_loop().run_until_complete(dl.dl_loop()) File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete return future.result() File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytr\dl.py", line 59, in dl_loop await self.tl.get_next_timeline(max_age_timestamp=self.since_timestamp) File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytr\utils.py", line 236, in get_next_timeline await self.tr.timeline() File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytr\api.py", line 443, in timeline return await self.subscribe({'type': 'timeline', 'after': after}) File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytr\api.py", line 293, in subscribe ws = await self._get_ws() File "C:\Users\xxxxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\pytr\api.py", line 279, in _get_ws raise ValueError(f'Connection Error: {response}') ValueError: Connection Error: failed 29 Segmentation fault

To Reproduce Steps to reproduce the behavior:

Ran the command pytr dl_docs .

Environment

Additional context Tried python 3.7 python 3.9 and python 3.11 It seems that after the Trade Repbulic update they changed the API?!

hansgans007 commented 9 months ago

Connecting to websocket ... Traceback (most recent call last): File "C:\Python39\Scripts\pytr-script.py", line 33, in sys.exit(load_entry_point('pytr==0.1.5', 'console_scripts', 'pytr')()) File "C:\Python39\lib\site-packages\pytr\main.py", line 206, in main asyncio.get_event_loop().run_until_complete(dl.dl_loop()) File "C:\Python39\lib\asyncio\base_events.py", line 641, in run_until_complete return future.result() File "C:\Python39\lib\site-packages\pytr\dl.py", line 59, in dl_loop await self.tl.get_next_timeline(max_age_timestamp=self.since_timestamp) File "C:\Python39\lib\site-packages\pytr\utils.py", line 236, in get_next_timeline await self.tr.timeline() File "C:\Python39\lib\site-packages\pytr\api.py", line 443, in timeline return await self.subscribe({'type': 'timeline', 'after': after}) File "C:\Python39\lib\site-packages\pytr\api.py", line 293, in subscribe ws = await self._get_ws() File "C:\Python39\lib\site-packages\pytr\api.py", line 279, in _get_ws raise ValueError(f'Connection Error: {response}') ValueError: Connection Error: failed 29

on me

windows 10 python3.9

GordonInDaHouse commented 9 months ago

Same here.

Login seems to work. But everything else results in "failed 29".

fft1010 commented 9 months ago

Hi, Same here on Mac. I can confirm, that it worked yesterday morning (last download 11:13 german time and the days before) but than next time 13:13 (did a reboot, this is why I know the exact time) I wanted to use it yesterday, it did not work any more. Same errors as above. Did not change anything or update on the Mac in between.

thanks Juergen

nospam999 commented 9 months ago

I have the same issue. Perhaps it has to do with the new traderepublic app that was recently launched ....?

rhpl commented 9 months ago

I had also the following error:

ValueError: Connection Error: failed 29

When you look in the traceback it points to api.py:249

Since the error is regarding the websocket connect function i looked in the devtools for the webapplication of TR. There it said it connects on 28 - Atleast for me...

So back to the api.py file. A littlebit over the error line (line 272) you find connect_id = 22. I tried to change it to 29 since this is what the error said. Result is it worked after saving the file.

I also tried 28 and 24, which also worked... It just didnt work for 21 or 22. So I dont exactly know why those numbers are not working but i think something changed on TR side.

I would have done a change request or smth... but i have never done this. Maybe someone smarter who is reading this can take over from here on.

Greetings

parodev93 commented 9 months ago

Good finding. Once i have checked it i will do a PR. Is this repo still be maintained? As i can still see old PRs which doesnt be merged yet i guess no one gona merge mine. Lets see, at least we have a solution.

Edit: after testing worked fine with id 29 PR Connection Error: failed 29 #43

GordonInDaHouse commented 9 months ago

So back to the api.py file. A littlebit over the error line (line 272) you find connect_id = 22. I tried to change it to 29 since this is what the error said. Result is it worked after saving the file.

I also tried 28 and 24, which also worked... It just didnt work for 21 or 22. So I dont exactly know why those numbers are not working but i think something changed on TR side.

Working for me as well. Thanks for the solution!

G-Ultimatee commented 9 months ago

Can someone tell me, how to integrate the mentioned adjustments in my Win11 Python? I am not that good in python. Just installed this long time ago for trade republic. Thanks

fft1010 commented 9 months ago

So back to the api.py file. A littlebit over the error line (line 272) you find connect_id = 22. I tried to change it to 29 since this is what the error said. Result is it worked after saving the file. I also tried 28 and 24, which also worked... It just didnt work for 21 or 22. So I dont exactly know why those numbers are not working but i think something changed on TR side.

Working for me as well. Thanks for the solution!

HI, works here as well. Very easy, even no programmers can do the change, IMHO (I am non programmer :-) )

thanks a bunch Juergen

fft1010 commented 9 months ago

Can someone tell me, how to integrate the mentioned adjustments in my Win11 Python? I am not that good in python. Just installed this long time ago for trade republic. Thanks

Hi, in the error it says somewhere at the end:

File "/usr/local/lib/python3.10/site-packages/pytr/api.py", line 279, in _get_ws
    raise ValueError(f'Connection Error: {response}')
ValueError: Connection Error: failed 29

which gives you the path where the api.py file is sitting. Make a copy of this file api.py file, if the following does not work Take an editor (notepad, vi, ... NOT WORD) and edit this api.py (original, not copy). Go to line 272 in this file. You should see something like: connect_id = 22 or serach for this line, if it is not there. Than change the 22 to a 29 so that it looks like connect_id = 29

save the file and start again. Worked for me, and a couple of others immediately.

thanks Juergen

SixGunChief commented 9 months ago

Can someone tell me, how to integrate the mentioned adjustments in my Win11 Python? I am not that good in python. Just installed this long time ago for trade republic. Thanks

Hi, in the error it says somewhere at the end: [...schnipp...] save the file and start again. Worked for me, and a couple of others immediately.

Well explained, even for beginners. Also worked for me immediately. Thank you from the sunny beach of the Baltic Sea.

mrdjv2 commented 9 months ago

Can someone tell me, how to integrate the mentioned adjustments in my Win11 Python? I am not that good in python. Just installed this long time ago for trade republic. Thanks

Hi, in the error it says somewhere at the end:

File "/usr/local/lib/python3.10/site-packages/pytr/api.py", line 279, in _get_ws
  raise ValueError(f'Connection Error: {response}')
ValueError: Connection Error: failed 29

which gives you the path where the api.py file is sitting. Make a copy of this file api.py file, if the following does not work Take an editor (notepad, vi, ... NOT WORD) and edit this api.py (original, not copy). Go to line 272 in this file. You should see something like: connect_id = 22 or serach for this line, if it is not there. Than change the 22 to a 29 so that it looks like connect_id = 29

save the file and start again. Worked for me, and a couple of others immediately.

thanks Juergen

(base) C:\Users\xxx>pytr portfolio 17:44:40 Found credentials file 17:44:40 Phone: +49***, PIN: **** 17:44:40 Web session resumed 17:44:40 Logged in 17:44:40 Connecting to websocket ... 17:44:40 Connected to websocket ... 17:44:40 Received error message: '1 E {"errors":[{"errorCode":"BAD_SUBSCRIPTION_TYPE","errorField":null,"errorMessage":"Unknown topic type","meta":{"source":"MAPPER"}}]}' Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "C:\Users\xxx\anaconda3\Scripts\pytr.exe__main__.py", line 7, in File "C:\Users\xxx\anaconda3\Lib\site-packages\pytr\main.py", line 215, in main Portfolio(login(phone_no=args.phone_no, pin=args.pin, web=not args.applogin)).get() File "C:\Users\xxx\anaconda3\Lib\site-packages\pytr\portfolio.py", line 73, in get asyncio.get_event_loop().run_until_complete(self.portfolio_loop()) File "C:\Users\xxx\anaconda3\Lib\asyncio\base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\xxx\anaconda3\Lib\site-packages\pytr\portfolio.py", line 16, in portfolio_loop _subscription_id, subscription, response = await self.tr.recv() ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\xxx\anaconda3\Lib\site-packages\pytr\api.py", line 352, in recv raise TradeRepublicError(subscription_id, subscription, payload) pytr.api.TradeRepublicError: ('1', {'type': 'portfolio'}, {'errors': [{'errorCode': 'BAD_SUBSCRIPTION_TYPE', 'errorField': None, 'errorMessage': 'Unknown topic type', 'meta': {'source': 'MAPPER'}}]})

Changing 22 to 29 doesn't work for me... :-(

fft1010 commented 9 months ago

Can someone tell me, how to integrate the mentioned adjustments in my Win11 Python? I am not that good in python. Just installed this long time ago for trade republic. Thanks

Hi, can you copy back the original "api.py" file, and send the error messages here? If it does show the "22" the given solution should work. If you have Windows, what might be the problem is, that the line ends are wrong, as windows has different line ends than unix. (Just an assumption, but I myself had this a couple of times.)

Try to download and install this editor

https://visualstudio.microsoft.com/de/downloads/

this recognizes the correct line ends IMHO also on windows. And use this editor for editing the api.py file.

thanks Juergen

GordonInDaHouse commented 9 months ago

File "C:\Users\xxx\anaconda3\Lib\site-packages\pytr\api.py", line 352, in recv raise TradeRepublicError(subscription_id, subscription, payload) pytr.api.TradeRepublicError: ('1', {'type': 'portfolio'}, {'errors': [{'errorCode': 'BAD_SUBSCRIPTION_TYPE', 'errorField': None, 'errorMessage': 'Unknown topic type', 'meta': {'source': 'MAPPER'}}]})

Be careful. Don't mess up things.

We discuss here the problem with "ValueError: Connection Error: failed 29". This will get solved with changing the 21/22 to 29.

If you get an error with BAD_SUBSCRIPTION_TYPE, then this problem here is solved already. The portfolio is not available since they changed the API and will return this BAD_SUBSCRIPTION_TYPE error.

deka-xD commented 9 months ago

Hi,

The error “BAD_SUBSCRIPTION_TYPE” was solved with the miry fork version. But I think the issue is back now.

Changing the ID to 29 solves the error for command “dl_docs”.

After this “Connection Error: failed 29” - , even with the fork version, doesn't work.

Can someone confirm this?

PhilippS93 commented 9 months ago

Hi,

The error “BAD_SUBSCRIPTION_TYPE” was solved with the miry fork version. But I think the issue is back now.

Changing the ID to 29 solves the error for command “dl_docs”.

After this “Connection Error: failed 29” - , even with the fork version, doesn't work.

Can someone confirm this?

Have you tried to install all dependencies again after editing the file? For me, it is working now.

deka-xD commented 9 months ago

Unfortunately, no. I changed the connect id and installed with this method again.

$ pip3 install . $ pytr -v debug portfolio

But I am getting the same error as before.

fft1010 commented 9 months ago

Hi,

Can someone confirm this?

Hi, I just tried:

pytr portfolio

and got

Received error message: '1 E {"errors":[{"errorCode":"BAD_SUBSCRIPTION_TYPE","errorField":null,"errorMessage":"Unknown topic type","meta":{"source":"MAPPER"}}]}'
Traceback (most recent call last):
  File "/usr/local/bin/pytr", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/pytr/main.py", line 215, in main
    Portfolio(login(phone_no=args.phone_no, pin=args.pin, web=not args.applogin)).get()
  File "/usr/local/lib/python3.10/site-packages/pytr/portfolio.py", line 73, in get
    asyncio.get_event_loop().run_until_complete(self.portfolio_loop())
  File "/usr/local/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.10/site-packages/pytr/portfolio.py", line 16, in portfolio_loop
    _subscription_id, subscription, response = await self.tr.recv()
  File "/usr/local/lib/python3.10/site-packages/pytr/api.py", line 352, in recv
    raise TradeRepublicError(subscription_id, subscription, payload)
pytr.api.TradeRepublicError: ('1', {'type': 'portfolio'}, {'errors': [{'errorCode': 'BAD_SUBSCRIPTION_TYPE', 'errorField': None, 'errorMessage': 'Unknown topic type', 'meta': {'source': 'MAPPER'}}]})

As I am not a programmer, I was happy, that the automated doc DL worked again with the "29", I never used anything else.

thanks Juergen

deka-xD commented 8 months ago
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\xxxxx\AppData\Local\Programs\Python\Python312-arm64\Scripts\pytr.exe\__main__.py", line 7, in <module>
  File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python312-arm64\Lib\site-packages\pytr\main.py", line 215, in main
    Portfolio(login(phone_no=args.phone_no, pin=args.pin, web=not args.applogin)).get()
  File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python312-arm64\Lib\site-packages\pytr\portfolio.py", line 120, in get
    asyncio.get_event_loop().run_until_complete(self.portfolio_loop())
  File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python312-arm64\Lib\asyncio\base_events.py", line 664, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python312-arm64\Lib\site-packages\pytr\portfolio.py", line 57, in portfolio_loop
    pos['netValue'] = response['last']['price'] * pos['netSize']
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
TypeError: can't multiply sequence by non-int of type 'str'

Still getting the frozen runpy error after debugging portfolio.

marzzzello commented 8 months ago

Fixed in latest version