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

High rate of failures for API calls #10

Open
oshepotylo opened this issue Aug 31, 2023 · 0 comments
Open

High rate of failures for API calls #10

oshepotylo opened this issue Aug 31, 2023 · 0 comments

Comments

@oshepotylo
Copy link

Describe the bug
API calls often do not go through. For instance in the code below, which downloads UK trade data by months, the code stops at arbitrary month, which is different every time, and I never have been able to complete it:

for year in range(2017, 2023):
for month in range(1, 13):
month_str = f'{year}{month:02d}'
dfexp=comtradeapicall.getFinalData(subscription_key=key,
typeCode='C',
freqCode='M',
flowCode = 'X',
clCode='HS',
cmdCode = None,
period = month_str,
reporterCode = 826,
partnerCode = None,
partner2Code = None,
customsCode = None,
motCode = None,
breakdownMode = 'classic'
)
data_list.append(dfexp)
print(str(month_str)+ " - Export - " + str(len(dfexp)))

The code stopped at April 2018 (can be any other time period really) with the following

runfile('C:/Users/shepotyo/Dropbox/2023 UK Trade after Brexit/py/UK_data_by_country.py', wdir='C:/Users/shepotyo/Dropbox/2023 UK Trade after Brexit/py')
201701 - Export - 190320
201702 - Export - 195504
201703 - Export - 204953
201704 - Export - 198195
201705 - Export - 200046
201706 - Export - 199866
201707 - Export - 199204
201708 - Export - 199385
201709 - Export - 199897
201710 - Export - 203761
201711 - Export - 205113
201712 - Export - 197875
201801 - Export - 195559
201802 - Export - 196753
201803 - Export - 204714
201804 - Export - 200388
Error in calling API: https://comtradeapi.un.org/data/v1/get/C/M/HS?reportercode=826&flowCode=X&period=201805&breakdownMode=classic&subscription-key=key
Traceback (most recent call last):

File ~\Anaconda3\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)

File c:\users\shepotyo\dropbox\2023 uk trade after brexit\py\uk_data_by_country.py:26
print(str(month_str)+ " - Export - " + str(len(dfexp)))

TypeError: object of type 'NoneType' has no len()

Desktop (please complete the following information):

  • OS: Windows 10
  • Python version 3.9
  • Version 1.0.19

Additional context
Perhaps you can help me to modify the code, so the call runs in a cycle until success?

@oshepotylo oshepotylo changed the title Oleksandr Shepotylo High rate of failures for API calls Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant