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

"Error: API call executed successfully, but did not return expected json format" when using wb_stat to download data #43

Open
JacopoDior opened this issue Feb 18, 2024 · 2 comments

Comments

@JacopoDior
Copy link

Hello,

when trying to download indicators using the command wb_data I receive the following error:
Error: API call executed successfully, but did not return expected json format

For instance when I try to reproduce the line of code available in the help:
wb_data("NY.GDP.MKTP.CD")

@luifrancgom
Copy link

luifrancgom commented Feb 19, 2024

I am having the same problem when using the package. However I try with the package WDI and a similar problem happens:

With wbstats:

library(wbstats)
wb_data(indicator = "NY.GDP.MKTP.CD", 
        country = "BR", 
        start_date = 2021, 
        end_date = 2021)
#> Error: API call executed successfully, but did not return expected json format

Created on 2024-02-18 with reprex v2.1.0

With WDI

library(WDI)
WDI(indicator = "NY.GDP.MKTP.CD", 
    country = "BR", 
    start = 2021, 
    end = 2021)
#> Error in WDI(indicator = "NY.GDP.MKTP.CD", country = "BR", start = 2021, : The following indicators could not be downloaded: NY.GDP.MKTP.CD.
#> 
#> Please make sure that you are running the latest version of the `WDI` package, and that the arguments you are using in the `WDI()` function are valid.
#> 
#> Sometimes, downloads will suddenly stop working, even if nothing has changed in the R code of the WDI package. ("The same WDI package version worked yesterday!") In those cases, the problem is almost certainly related to the World Bank servers or to your internet connection.
#> 
#> You can check if the World Bank web API is currently serving the indicator(s) of interest by typing a URL of this form in your web browser:
#> 
#> https://api.worldbank.org/v2/en/country/all/indicator/NY.GDP.MKTP.CD?format=json&date=:&per_page=32500&page=1

Created on 2024-02-18 with reprex v2.1.0

I think the problem is in te API taking into account that a similar problem happens with the package wbgapi from Python:

import wbgapi as wb

wb.data.DataFrame(series = "NY.GDP.MKTP.CD",
                  economy = "BRA",
                  time = range(2021, 2021))
Traceback (most recent call last): File "C:\Users\Usuario\ANACON~1\Lib\site-packages\requests\models.py", line 971, in json return complexjson.loads(self.text, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Usuario\ANACON~1\Lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Usuario\ANACON~1\Lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Usuario\ANACON~1\Lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 8 column 1 (char 9)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Usuario\ANACON1\Lib\site-packages\wbgapi_init_.py", line 533, in _queryAPI
result = response.json()
^^^^^^^^^^^^^^^
File "C:\Users\Usuario\ANACON
1\Lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 8 column 1 (char 9)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Usuario\ANACON1\Lib\site-packages\wbgapi\data.py", line 334, in DataFrame
for row in fetch(series, economy, time, mrv=mrv, mrnev=mrnev, skipBlanks=skipBlanks, labels=True, skipAggs=skipAggs, numericTimeKeys=numericTimeKeys, params=params, db=db, **dimensions):
File "C:\Users\Usuario\ANACON
1\Lib\site-packages\wbgapi\data.py", line 92, in fetch
for row in w.refetch(url, keys, params=params_, **values):
File "C:\Users\Usuario\ANACON1\Lib\site-packages\wbgapi_init_.py", line 322, in refetch
for row in fetch(url2, params, concepts, lang):
File "C:\Users\Usuario\ANACON
1\Lib\site-packages\wbgapi_init_.py", line 281, in fetch
(hdr,result) = queryAPI(url)
^^^^^^^^^^^^^^^
File "C:\Users\Usuario\ANACON~1\Lib\site-packages\wbgapi_init_.py", line 535, in _queryAPI
raise APIResponseError(url, 'JSON decoding error')
wbgapi.APIResponseError: APIError: JSON decoding error (https://api.worldbank.org/v2/en/sources/2/series/NY.GDP.MKTP.CD/country/BRA/time/?per_page=1000&page=1&format=json)

@luifrancgom
Copy link

Apparently the problem has been solve. Now the data can be downloaded without problem.

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

2 participants