Finished call to 'dbnomics._fetch_response'

Hi,

I am facing an issue with library. Hope someone can help.
I have installed DBnomics libaray and trying to run the first sample code that I found in the documentation at this link.
However, I am getting the following error:

Could not fetch data from URL ‘https://api.db.nomics.world/v22/series/OECD/MEI/USA.B6BLTT01.CXCUSA.Q?observations=1&offset=0

However, if I paste that exact URL in the browser, I get a successful response with the data. Am I doing something wrong or it’s a problem related to the library?

Code:
import dbnomics
dbnomics.fetch_series(‘OECD’, ‘MEI’, ‘USA.B6BLTT01.CXCUSA.Q’)

Screenshot:


Hi @gb1 and welcome to the DBnomics community!

Thanks for your detailed error report.

I just tried the code snippet, and it worked as in the docs.

Could you please retry? I suspect that it was a temporary high load on DBnomics that caused the inability to load data.

I tried again before and after reinstalling the library but still seeing the same error.

Error.pdf (107.3 KB)

However I noticed that this happens only on my local jupyter. I tried the same query on Colab and it worked seamlessly.

In the error stack trace you attached (Error.pdf), the “real” error is:

File ~\anaconda3\lib\site-packages\dbnomics\__init__.py:572, in _fetch_response(url, timeout)
570
timeout = default_timeout
--> 572 response = httpx.get(url, follow_redirects=True, timeout=timeout)
574 if response.status_code in {429, 500, 502, 503, 504}:
TypeError: get() got an unexpected keyword argument 'follow_redirects'

This makes me think that a wrong version of the httpx dependency could be installed.

However I could not reproduce the problem.
Doing it myself, here is my command-line logs from scratch:

$ python -V      
Python 3.11.6

$ virtualenv dbnomics-venv
$ . ./dbnomics-venv/bin/activate

$ pip install dbnomics
[...]

# Checking the versions of the dependencies
$ pip list
Package         Version
--------------- ------------
anyio           4.2.0
certifi         2023.11.17
dbnomics        1.2.5
h11             0.14.0
httpcore        1.0.2
httpx           0.26.0
idna            3.6
numpy           1.26.3
pandas          2.1.4
pip             23.3.2
python-dateutil 2.8.2
pytz            2023.3.post1
setuptools      69.0.3
six             1.16.0
sniffio         1.3.0
tenacity        8.2.3
tzdata          2023.4
wheel           0.42.0

$ python  
Python 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbnomics
>>> dbnomics.fetch_series('OECD', 'MEI', 'USA.B6BLTT01.CXCUSA.Q')
    @frequency provider_code dataset_code  ...                                            Subject                                           Measure  Frequency
0    quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
1    quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
2    quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
3    quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
4    quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
..         ...           ...          ...  ...                                                ...                                               ...        ...
250  quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
251  quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
252  quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
253  quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly
254  quarterly          OECD          MEI  ...  Balance of payments BPM6 > Current account Bal...  US Dollars, sum over component sub-periods, s.a.  Quarterly

[255 rows x 18 columns]
>>> 

How did you install the dbnomics module locally? What’s your Python version (because older Python versions could lead to an older version of httpx also)?

PS: just for your information, instead of a screenshot or a PDF, which are not very convenient to read and copy-paste, the idiomatic way to attach source code in forum messages is by using “fenced code blocks”, cf docs

1 Like

That fixed the issue, thanks!