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

UnboundLocalError #71

Closed
mor3dr3ad opened this issue Jun 12, 2024 · 16 comments
Closed

UnboundLocalError #71

mor3dr3ad opened this issue Jun 12, 2024 · 16 comments
Labels
bug Something isn't working

Comments

@mor3dr3ad
Copy link

Description of the bug
A clear and concise description of what the bug is.

Failure when trying to download files. UnboundLocalError.

To Reproduce
Steps to reproduce the behavior:
Running ArchLinux with pytr installed via pip.

  1. Go to 'any location'
  2. Ran the command pytr dl_docs ./
  3. See error

Expected behavior
A clear and concise description of what you expected to happen.

Error log

23:43:48 Connecting to websocket ...
23:43:48 Connected to websocket ...
23:43:48 Received error message: '1 E {"errors":[{"errorCode":"UNKNOWN_ERROR","errorField":null,"errorMessage":"Unknown error","meta":{"source":"PLATFORM"}}]}'
23:43:48 ('1', {'type': 'timeline', 'after': None}, {'errors': [{'errorCode': 'UNKNOWN_ERROR', 'errorField': None, 'errorMessage': 'Unknown error', 'meta': {'source': 'PLATFORM'}}]})
Traceback (most recent call last):
  File "/home/xxx/.local/bin/pytr", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/xxx/.local/lib/python3.12/site-packages/pytr/main.py", line 208, in main
    asyncio.get_event_loop().run_until_complete(dl.dl_loop())
  File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/xxx/.local/lib/python3.12/site-packages/pytr/dl.py", line 77, in dl_loop
    if subscription['type'] == 'timeline':
       ^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'subscription' where it is not associated with a value


Environment

  • OS: arch linux 6.9.3-arch1-1
  • pytr version: 0.1.9

Additional context
Add any other context about the problem here.

@mor3dr3ad mor3dr3ad added the bug Something isn't working label Jun 12, 2024
@pgoodbread
Copy link

pgoodbread commented Jun 14, 2024

I can reproduce this on
OS: macOS Sonoma 14.4.1, M3 Silicon
pytr version: 0.1.9

My error message and stack:

10:22:29 Received error message: '1 E {"errors":[{"errorCode":"UNKNOWN_ERROR","errorField":null,"errorMessage":"Unknown error","meta":{"source":"PLATFORM"}}]}'
10:22:29 ('1', {'type': 'timeline', 'after': None}, {'errors': [{'errorCode': 'UNKNOWN_ERROR', 'errorField': None, 'errorMessage': 'Unknown error', 'meta': {'source': 'PLATFORM'}}]})
Traceback (most recent call last):
  File "/Users/pgoodbread/Library/Python/3.9/bin/pytr", line 8, in <module>
    sys.exit(main())
  File "/Users/pgoodbread/Library/Python/3.9/lib/python/site-packages/pytr/main.py", line 208, in main
    asyncio.get_event_loop().run_until_complete(dl.dl_loop())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/pgoodbread/Library/Python/3.9/lib/python/site-packages/pytr/dl.py", line 77, in dl_loop
    if subscription['type'] == 'timeline':
UnboundLocalError: local variable 'subscription' referenced before assignment

@mor3dr3ad
Copy link
Author

My best guess would be that TradeRepublic has made some changes in their api and therefore the subscriptions varriable in api.py does not get populated correctly anymore. However, I have not had a closer look at how the data is obtained or how the traderepublic api works.

@fft1010
Copy link

fft1010 commented Jun 14, 2024

HI,
yes TR definitely changed something. Another (browser based tool), cannot download the docs since 8th june 2024 as well. They also somehow changed the PDF format, so that portfolio performance could not read it. But this is fixed this today.

sorry, I cannot help more than that, as I am not a programmer.

thaks
Juergen

@mor3dr3ad
Copy link
Author

@marzzzello : if you walk me through where you get your data via the 'private traderepublic api', I can contribute

@nospam999
Copy link

Same problem here at Windows 11:
C:\Users\juergen>pytr dl_docs H:\Juergen\Finanzen\traderepublic_juergen_downloads --last_days 60 21:15:27 Found credentials file 21:15:27 Phone: +49159********, PIN: **** 21:15:27 Web session resumed 21:15:27 Logged in 21:15:27 Found 3724 lines in history file 21:15:27 Awaiting #1 timeline 21:15:27 Connecting to websocket ... 21:15:27 Connected to websocket ... 21:15:27 Received error message: '1 E {"errors":[{"errorCode":"UNKNOWN_ERROR","errorField":null,"errorMessage":"Unknown error","meta":{"source":"PLATFORM"}}]}' 21:15:27 ('1', {'type': 'timeline', 'after': None}, {'errors': [{'errorCode': 'UNKNOWN_ERROR', 'errorField': None, 'errorMessage': 'Unknown error', 'meta': {'source': 'PLATFORM'}}]}) Traceback (most recent call last): File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Python310\Scripts\pytr.exe\__main__.py", line 7, in <module> File "C:\Python310\lib\site-packages\pytr\main.py", line 208, in main asyncio.get_event_loop().run_until_complete(dl.dl_loop()) File "C:\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete return future.result() File "C:\Python310\lib\site-packages\pytr\dl.py", line 77, in dl_loop if subscription['type'] == 'timeline': UnboundLocalError: local variable 'subscription' referenced before assignment

@retrogamer1337
Copy link

While with my TR account everything works fine, on the same machine I get the error above with the account of my girlfriend. It seems that this also depends on the used tr account.

@olivermuc
Copy link

olivermuc commented Jun 23, 2024

Same here.
Could this have to do with the new "Giro-Konto" upgrade they offer?
Hope that someone finds a fix.

@retrogamer1337
Copy link

Same here. Could this have to do with the new "Giro-Konto" upgrade they offer? Hope that someone finds a fix.

This might be the case, I did the Giro upgrade while my girlfriend did not get the information about this yet.

@UiX689
Copy link

UiX689 commented Jun 23, 2024

Got the same error message but I've already updated to Giro. :/

@olivermuc
Copy link

I can confirm, the pull req #74 seems to fix the issues.
"seems" because I didn't test all features & functions, but standard operation works like a charm again.
If you're somewhat familiar with GIT and pip, it's easy to download locally and install.

@fft1010
Copy link

fft1010 commented Jun 24, 2024

HI,
I did a
pip uninstall pytr
and a
pip install pytr

But the version number did not change. It still shows

pytr -V
0.1.9
14:46:08 pytr is up to date

Anything else I need to do?
(The "Abrechnung" PDFs are still not downloaded, this is why I am asking.)

thanks
Juergen

@olivermuc
Copy link

HI, I did a pip uninstall pytr and a pip install pytr

But the version number did not change.

That's because the pull request has not been approved/incorporated by the (original) author yet.

What you can do meanwhile:

  1. clone a local repo with & cd to it:
    git clone https://github.com/pytr-org/pytr.git
    cd pytr
  2. fetch the pull req as a branch:
    git fetch origin pull/74/head:datastructure-fix-formating
  3. change branch:
    git checkout datastructure-fix-formating
  4. install from local source if you're using pip:
    pip install -e .

Before item 4. (pip install) I did edit ./setup.py and changed the version number to 0.1.9.1 - just to be sure, you may not need to though.

@fft1010
Copy link

fft1010 commented Jun 24, 2024

Hi @olivermuc ,
thanks a lot.

This does:
17:11:16 Received #88 timeline, awaiting #89 timeline
17:11:16 Received #89 (last) timeline
17:11:16    1/2648: Einzahlung/Auszahlung -- 
17:11:16    2/2648: Einzahlung/Auszahlung -- 
Traceback (most recent call last):

and than

Traceback (most recent call last):
  File "/opt/homebrew/bin/pytr", line 33, in <module>
    sys.exit(load_entry_point('pytr', 'console_scripts', 'pytr')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ry90/egeling.cloud/portfolio-performance/2024-trade-republic/pytr/pytr/main.py", line 211, in main
    asyncio.get_event_loop().run_until_complete(dl.dl_loop())
  File "/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/ry90/egeling.cloud/portfolio-performance/2024-trade-republic/pytr/pytr/dl.py", line 80, in dl_loop
    await self.tl.timelineDetail(response, self, max_age_timestamp=self.since_timestamp)
  File "/Users/ry90/egeling.cloud/portfolio-performance/2024-trade-republic/pytr/pytr/utils.py", line 323, in timelineDetail
    title_text = self.get_title_text(response)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ry90/egeling.cloud/portfolio-performance/2024-trade-republic/pytr/pytr/utils.py", line 399, in get_title_text
    raise RuntimeError('Unable to detect titleText from response')
RuntimeError: Unable to detect titleText from response

as you might think, I have no clue :-) Hopefully someone else

(Just plain TR, no Banking, no credit card.)
Version 0.1.9 did not gave errors, but also did not DL die "Abrechnungen" but downloaded other PDFs

thanks
Juergen

@mor3dr3ad
Copy link
Author

Hi @olivermuc , thanks a lot.

This does:
17:11:16 Received #88 timeline, awaiting #89 timeline
17:11:16 Received #89 (last) timeline
17:11:16    1/2648: Einzahlung/Auszahlung -- 
17:11:16    2/2648: Einzahlung/Auszahlung -- 
Traceback (most recent call last):

and than

Traceback (most recent call last):
  File "/opt/homebrew/bin/pytr", line 33, in <module>
    sys.exit(load_entry_point('pytr', 'console_scripts', 'pytr')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ry90/egeling.cloud/portfolio-performance/2024-trade-republic/pytr/pytr/main.py", line 211, in main
    asyncio.get_event_loop().run_until_complete(dl.dl_loop())
  File "/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/ry90/egeling.cloud/portfolio-performance/2024-trade-republic/pytr/pytr/dl.py", line 80, in dl_loop
    await self.tl.timelineDetail(response, self, max_age_timestamp=self.since_timestamp)
  File "/Users/ry90/egeling.cloud/portfolio-performance/2024-trade-republic/pytr/pytr/utils.py", line 323, in timelineDetail
    title_text = self.get_title_text(response)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ry90/egeling.cloud/portfolio-performance/2024-trade-republic/pytr/pytr/utils.py", line 399, in get_title_text
    raise RuntimeError('Unable to detect titleText from response')
RuntimeError: Unable to detect titleText from response

as you might think, I have no clue :-) Hopefully someone else

(Just plain TR, no Banking, no credit card.) Version 0.1.9 did not gave errors, but also did not DL die "Abrechnungen" but downloaded other PDFs

thanks Juergen

I can confirm - same for me after installing with pull request as above

@olivermuc
Copy link

(Just plain TR, no Banking, no credit card.) Version 0.1.9 did not gave errors, but also did not DL die "Abrechnungen" but downloaded other PDFs

Odd. Like I said, for me it was straight forward and I followed the exact steps outlined above.
However, different accounts could have different "profiles" per your trading and document history.

Since I can't replicate the issue you're (and @mor3dr3ad) is mentioning, I can't dig deeper. Also, I'd be worried if I -for debugging purposes- ran scripts (and auth requests) too rapidly, my account might get flagged 😬.

Perhaps @marzzzello can shed some light on what to watch out for when debugging?! Cheers-

@mats58
Copy link

mats58 commented Jun 26, 2024

Hi all,
first of all, thanks for this nice tool :-)
I used this tool not before and had also the mistake described in this issue here:

UnboundLocalError: local variable 'subscription' referenced before assignment

As workaround I installed the branch from #74
pipx install git+https://github.com/DayAft3r/pytr
So, this error above was gone, but another one came :-(
For details, please see my comment there #74 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants