Chavithra / degiro-connector

This is yet another library to access Degiro's API.
BSD 3-Clause "New" or "Revised" License
205 stars 46 forks source link

Faulty API call - AttributeError: 'NoneType' object has no attribute 'DESCRIPTOR'" #117

Closed ALL-Ventura closed 11 months ago

ALL-Ventura commented 11 months ago

Hi there, I'm facing an issue using the code.

I managed to get my client details, but the when I request the portfolio I get the error:

" message_descriptor = message.DESCRIPTOR
                         ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'DESCRIPTOR'"

I read the other issues and saw this happens whe there's a faulty API Call.

This is the code I'm using:


# IMPORTATIONS
import json
import logging
import os
import pandas as pd
import modules.tools as t
import degiro_connector.core.helpers.pb_handler as pb_handler

from degiro_connector.trading.api import API as TradingAPI
from degiro_connector.trading.models.trading_pb2 import Credentials, Update
from IPython.display import display

# SETUP LOGGING LEVEL
logging.basicConfig(level=logging.DEBUG)

# CONFIG DICT
config_path = os.path.join(os.getcwd(),"resources", "config_dict.json")
with open (config_path) as config_file:
    config_dict = json.load(config_file)

# SETUP CREDENTIALS
int_account = config_dict.get("int_account")
username = config_dict.get("username")
password = config_dict.get("password")
credentials = Credentials(
    int_account=int_account,
    username=username,
    password=password,
)
# CONNECTING TO TRADING API
trading_api = TradingAPI(credentials=credentials)
trading_api.connect()

def degiro_client_details():
    client_details_table = trading_api.get_client_details()
    df = pd.json_normalize(client_details_table['data'])
    return df.T

def degiro_get_portfolio():
    request_list = Update.RequestList()
    request_list.values.extend(
    [
        Update.Request(option=Update.Option.ORDERS, last_updated=0),
        Update.Request(option=Update.Option.PORTFOLIO, last_updated=0),
        Update.Request(option=Update.Option.TOTALPORTFOLIO, last_updated=0),
    ]
)
    update = trading_api.get_update(request_list=request_list, raw=False)
    update_dict = pb_handler.message_to_dict(message=update)

    if "orders" in update_dict:
        orders_df = pd.DataFrame(update_dict["orders"]["values"])
        print("orders")
        display(orders_df)

    if "portfolio" in update_dict:
        portfolio_df = pd.DataFrame(update_dict["portfolio"]["values"])
        print("portfolio")
        display(portfolio_df)

    if "total_portfolio" in update_dict:
        total_portfolio_df = pd.DataFrame(update_dict["total_portfolio"]["values"])
        print("total_portfolio")
        display(total_portfolio_df)

def degiro_filter_portfolio():
    pass

Does anyone have any idea how to handle this?

I asked Google's Bard and it said the "Proto message is not valid" (no idea what that means)

Thanks in advance

ALL-Ventura commented 11 months ago

I accidentally ran the code again and it's working.

I'm closing this issue :D