Automatic import of classifications

Hi guys, does anybody have any idea why this one file is not working?

I have e.g. the portfolio files of my kids and those files work without any problem.

Anybody any hint how it can be that that one portfolio is not working?

The file-not-found error is nonsense as the file is there in the same folder, etc. as the other files that work…

Any hint is highly appreciated!

C:\Users\marti>“C:\Users\marti\OneDrive\Investments\pp-classifier\portfolio-classifier.py” “C:\Users\marti\OneDrive\Investments\PP Depots\DepotMartin - Kopie.xml” “C:\Users\marti\OneDrive\Investments\PP Depots\DepotAnalyseMartin.xml”
Traceback (most recent call last):
File “C:\Users\marti\OneDrive\Investments\pp-classifier\portfolio-classifier.py”, line 729, in
pp_file = PortfolioPerformanceFile(args.input_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\marti\OneDrive\Investments\pp-classifier\portfolio-classifier.py”, line 557, in init
self.pp_tree = ET.parse(filepath)
^^^^^^^^^^^^^^^^^^
File “C:\Users\marti\AppData\Local\Programs\Python\Python311\Lib\xml\etree\ElementTree.py”, line 1218, in parse
tree.parse(source, parser)
File “C:\Users\marti\AppData\Local\Programs\Python\Python311\Lib\xml\etree\ElementTree.py”, line 569, in parse
source = open(source, “rb”)
^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: ‘C:\Users\marti\OneDrive\Investments\PP Depots\DepotMartin - Kopie.xml’

Would be really great when the python solution would work stable …

  • … also for single shares
  • … and most important, it should also updating already existing/imported classifications, so you can run it frequently after some months to update the classifications (to update top10 shares in the fonds/etf, to update percentatges of allocations, etc.).

Hi all, I tried the script today, but it is not running with the multifaktortest.xml. I get the following error messages:

PS C:\Users\becke\OneDrive\Dokumente\pp-portfolio-classifier-main> python portfolio-classifier.py test/multifaktortest.xml Traceback (most recent call last): File "C:\Users\becke\OneDrive\Dokumente\pp-portfolio-classifier-main\portfolio-classifier.py", line 731, in <module> pp_file.add_taxonomy(taxonomy) File "C:\Users\becke\OneDrive\Dokumente\pp-portfolio-classifier-main\portfolio-classifier.py", line 589, in add_taxonomy securities = self.get_securities() File "C:\Users\becke\OneDrive\Dokumente\pp-portfolio-classifier-main\portfolio-classifier.py", line 691, in get_securities security_h = security.load_holdings() File "C:\Users\becke\OneDrive\Dokumente\pp-portfolio-classifier-main\portfolio-classifier.py", line 351, in load_holdings self.holdings.load(isin = self.ISIN, secid = self.secid) File "C:\Users\becke\OneDrive\Dokumente\pp-portfolio-classifier-main\portfolio-classifier.py", line 418, in load bearer_token, secid = self.get_bearer_token(secid, domain) File "C:\Users\becke\OneDrive\Dokumente\pp-portfolio-classifier-main\portfolio-classifier.py", line 395, in get_bearer_token resultstringtoken = re.findall(token_regex, response.text)[0] IndexError: list index out of range

Can someone help me what could be the reason?

Thanks

Seems to be the same error I had. You have to change the portfolio-classifier.py file.

It is working.

Thanks a lot

Hello,
I am trying to use the script but so far I had no success.

When I try to install the libraries I get this :

PS C:\Users\Giuseppe\Desktop\pp-portfolio-classifier-main> py -m pip install -r requirements.txt
Requirement already satisfied: Jinja2==2.11.2 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from -r requirements.txt (line 1)) (2.11.2)
Requirement already satisfied: requests==2.24.0 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from -r requirements.txt (line 2)) (2.24.0)
Requirement already satisfied: requests-cache==0.5.2 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from -r requirements.txt (line 3)) (0.5.2)
Requirement already satisfied: jsonpath_ng==1.5.3 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from -r requirements.txt (line 4)) (1.5.3)
Requirement already satisfied: markupsafe==1.1.1 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from -r requirements.txt (line 5)) (1.1.1)
Requirement already satisfied: beautifulsoup4==4.9.3 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from -r requirements.txt (line 6)) (4.9.3)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from requests==2.24.0->-r requirements.txt (line 2)) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from requests==2.24.0->-r requirements.txt (line 2)) (2.10)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from requests==2.24.0->-r requirements.txt (line 2)) (1.25.11)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from requests==2.24.0->-r requirements.txt (line 2)) (2024.2.2)
Requirement already satisfied: ply in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from jsonpath_ng==1.5.3->-r requirements.txt (line 4)) (3.11)
Requirement already satisfied: decorator in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from jsonpath_ng==1.5.3->-r requirements.txt (line 4)) (5.1.1)
Requirement already satisfied: six in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from jsonpath_ng==1.5.3->-r requirements.txt (line 4)) (1.16.0)
Requirement already satisfied: soupsieve>1.2 in c:\users\giuseppe\appdata\local\programs\python\python312\lib\site-packages (from beautifulsoup4==4.9.3->-r requirements.txt (line 6)) (2.5)
PS C:\Users\Giuseppe\Desktop\pp-portfolio-classifier-main>

Then I try to run the script:

PS C:\Users\Giuseppe\Desktop\pp-portfolio-classifier-main> py portfolio-classifier.py Portfolio
C:\Users\Giuseppe\Desktop\pp-portfolio-classifier-main\portfolio-classifier.py:331: SyntaxWarning: invalid escape sequence ‘{’
secid = re.search(‘{“i”:“([^”]+)"’, response).group(1)
Traceback (most recent call last):
File “C:\Users\Giuseppe\Desktop\pp-portfolio-classifier-main\portfolio-classifier.py”, line 11, in
import requests
File “C:\Users\Giuseppe\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests_init_.py”, line 43, in
import urllib3
File “C:\Users\Giuseppe\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3_init_.py”, line 7, in
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File “C:\Users\Giuseppe\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\connectionpool.py”, line 11, in
from .exceptions import (
File “C:\Users\Giuseppe\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\exceptions.py”, line 2, in
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
ModuleNotFoundError: No module named ‘urllib3.packages.six.moves’
PS C:\Users\Giuseppe\Desktop\pp-portfolio-classifier-main>

Can someone help me?

1 Like

Did you adjust the Regex as recommended in the thread?

I have the same problem as Blackter3 with the multifaktortest.xml. And i already adjusted the Regex as recommended before

Ok so I managed to fix the issue. This line

No module named ‘urllib3.packages.six.moves’

made me think that the issue was not the script (i modified line 394 as suggested above) but the urllib3 library. Even if it was installed, uninstalling and reinstalling it fixed my issue. @dj_piepsarm do you have the no module named error too?

I had the same error. But with your solution, it works. Thank you

RequestsDependencyWarning: urllib3 (2.2.1) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "

I still have this like “warning” but it doesnt do much it seems.
I tried also some fixing with blackbox with installing and unistalling different packages, but the result is the same so i choose your fix

Hi all,

once the file it’s been updated with the classification, it’s possibile the use It as a default file and continue to modify It? thx

That’s correct Sir.

Cheers

1 Like

Thanks. I’m a noob. In this part of your instruction “ py portfolio-classifier.py <input_file>” . where I have to copy my input Xxx.xml file ? I put it in c:\ …. It seems not working. In the case it is correct to put it in c:\ … is it correct to write “ py portfolio-classifier.py c:\test.xml . Thanks

try a backslash:
py portfolio-classifier.py c:/test.xml

Thanks. It is not working. I receive the same error message.

$ py portfolio-classifier.py C:/Test.xml
C:\Users\samue\OneDrive\GIT\portfolio-classifier.py:331: SyntaxWarning: invalid escape sequence ‘{’
secid = re.search(‘{“i”:“([^”]+)"’, response).group(1)
Traceback (most recent call last):
File “C:\Users\samue\OneDrive\GIT\portfolio-classifier.py”, line 11, in
import requests
File “C:\Users\samue\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests_init_.py”, line 43, in
import urllib3
File “C:\Users\samue\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3_init_.py”, line 7, in
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File “C:\Users\samue\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\connectionpool.py”, line 11, in
from .exceptions import (
File “C:\Users\samue\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\exceptions.py”, line 2, in
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
ModuleNotFoundError: No module named ‘urllib3.packages.six.moves’

Can you help me to understand how to solve ?

Thanks

how can I adapt the search pattern ? I see the file portfolio-classifier but i don’t know how to open and adapt it.

It seems that the Morningstar pages look a bit a different now. So you need to adpat the search pattern in line 394 to something like:
token_regex = r"const maasToken \=\s\"(.+)\""

How you’re editing files? Basically right mouse click and edit for instance via wordpad

portfolio-classifier.py is a Python script. The script itself is in text form. So you need to open the file portfolio-classifier.py with any text editor (as explained by Rafa) and substitute line 394 with token_regex = r"const maasToken \=\s\"(.+)\"".

1 Like

thanks for your support but the problem is not solved. Probably i’m doing other mistakes. This is the message that I received . Can you help me to understand where is the error ?

$ py portfolio-classifier.py C:/Test.xml
C:\Users\samue\OneDrive\GIT\portfolio-classifier.py:331: SyntaxWarning: invalid escape sequence ‘{’
secid = re.search(‘{“i”:“([^”]+)"’, response).group(1)
Traceback (most recent call last):
File “C:\Users\samue\OneDrive\GIT\portfolio-classifier.py”, line 11, in
import requests
File “C:\Users\samue\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests_init_.py”, line 43, in
import urllib3
File “C:\Users\samue\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3_init_.py”, line 7, in
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File “C:\Users\samue\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\connectionpool.py”, line 11, in
from .exceptions import (
File “C:\Users\samue\AppData\Local\Programs\Python\Python312\Lib\site-packages\urllib3\exceptions.py”, line 2, in
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
ModuleNotFoundError: No module named ‘urllib3.packages.six.moves’