Error 'function' object has no attribute 'swagger_types'

hey devs
I’m using the python library to check the price of tokens, using the swagger_client.TokenApi (swagger_client.ApiClient (configuration)) function, I’m iterating a dictionary with a list of tokens with a quantity of 16 tokens, understanding that there is a limitation of call in the APIs that I inserted a time.sleep to not exceed the limit, however, after a few complete iterations in the dictionary, that is, it gets on average to iterate 10x the dictionary with 120 seconds time.sleep per complete iteration, the error below is returned.

Can you help me please?

Thanks.

Hi,
For me it looks like it gets to another limitation.
If you force an error by decreasing or removing the sleep you get the same error or a different one?
If you try a bigger sleep after 8 iterations it will get past 10 iterations or not?

1 Like

Hi,

Inside the code I was calling this function 5 more times within the iteration and I only passed it to one iteration and the error still happened.

Hi,
Can you give a minimal complete code example that has this problem?

Yes!

for example, basically I have a dictionary with the minimum information to be able to call the function and get the prices, as below.

smartContractDict = {
0:{‘address’: ‘0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82’, ‘chain’:‘bsc’, ‘chain_name’:‘mainnet’, ‘name’:“PancakeSwap”, ‘isVerify’: 0, ‘IsBuy’:0, ‘isSell’:0, ‘PriceVerify’:0.00, ‘PriceBuy’:0.00, ‘PriceSell’:0.00},
1:{‘address’: ‘0x2170ed0880ac9a755fd29b2688956bd959f933f8’, ‘chain’:‘bsc’, ‘chain_name’:‘mainnet’, ‘name’:“ETH-Binance”, ‘isVerify’: 0, ‘IsBuy’:0, ‘isSell’:0, ‘PriceVerify’:0.00, ‘PriceBuy’:0.00, ‘PriceSell’:0.00},

    }

then I simply save the price result in the variable “PriceAtual” and make comparisons only.

After going through x number of checks even with time.sleep it returns the error.

I made this Python script to get the price and I got no error for 20 runs:

import requests
import json
import time


smartContractDict = {
0:{"address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82", 
   "chain":"bsc", "chain_name":"mainnet", "name":"PancakeSwap", "isVerify": 0, "IsBuy":0, "isSell":0, "PriceVerify":0.00, "PriceBuy":0.00, "PriceSell":0.00},
1:{"address": "0x2170ed0880ac9a755fd29b2688956bd959f933f8", 
   "chain":"bsc", "chain_name":"mainnet", "name":"ETH-Binance", "isVerify": 0, "IsBuy":0, "isSell":0, "PriceVerify":0.00, "PriceBuy":0.00, "PriceSell":0.00},
}


def get_price(address, chain, chain_name):
    provider = 'https://deep-index.moralis.io/api/v2/erc20/%s/price?chain=bsc' % address

    headers = {
        "Content-Type": "application/json",
        "X-API-Key": "<YOUR_API_KEY_HERE>"
    }
    statusResponse = requests.request("GET", provider, headers=headers)
    data = statusResponse.json()
    print(json.dumps(data, indent=4))
    print("price =", data['usdPrice'])


for j in range(20):    
    print(j)
    for i in smartContractDict:
        address = smartContractDict[i]['address']
        chain = smartContractDict[i]['chain']
        chain_name = smartContractDict[i]['chain_name']
        print(i, address, chain, chain_name)
        get_price(address, chain, chain_name)
    time.sleep(1)

example of output:

0 0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82 bsc mainnet
{
    "nativePrice": {
        "value": "51763895777838418",
        "decimals": 18,
        "name": "Binance Coin",
        "symbol": "BNB"
    },
    "usdPrice": 23.367386736650246,
    "exchangeAddress": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
    "exchangeName": "PancakeSwap v2"
}
price = 23.367386736650246

1 Like

hey,

Thanks for the tip, I’m making the request directly, without using the python library for that, it’s working.

2 Likes