Search code examples
pythonpandaspython-requestssdmx

How can i access ECB Dataflow? TooManyRedirects: Exceeded 30 redirects


I am using Request package form pandasdmx library to to access some exchange rates from the European Central Bank. I tried to follow the stepts highlighted in the following walkthrough: https://pandasdmx.readthedocs.io/en/v1.0/walkthrough.html# bur it is giving me an error when i try to access the different dataflows. This is the code that i am using:

import pandasdmx as sdmx
ecb = sdmx.Request('ECB')
ecb_via_proxy = sdmx.Request('ECB',proxies={'http': 'http://1.2.3.4:5678'})
flow_msg = ecb.dataflow()


flow_msg = ecb.dataflow()
Traceback (most recent call last):

  File "<ipython-input-8-9011799aab2e>", line 1, in <module>
    flow_msg = ecb.dataflow()

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\pandasdmx\api.py", line 361, in get
    base_url, params=params, headers=headers, fromfile=fromfile)

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\pandasdmx\remote.py", line 98, in get
    url, params=params, headers=headers)

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\pandasdmx\remote.py", line 118, in request
    with closing(requests.get(url, params=params, **cur_config)) as response:

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\sessions.py", line 665, in send
    history = [resp for resp in gen] if allow_redirects else []

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\sessions.py", line 665, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []

  File "C:\Users\gcperez\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\sessions.py", line 166, in resolve_redirects
    raise TooManyRedirects('Exceeded {} redirects.'.format(self.max_redirects), response=resp)

TooManyRedirects: Exceeded 30 redirects.

I have used this kind of access many times before and nothing went wrong. ¿Anyone knows what could be happening?


Solution

  • The ECB changed its web service URL, and the version of pandaSDMX that you have does not have the current URL. I would suggest to use the sdmx1 package in which this issue was fixed > 7 months ago (see the diff here):

    $ pip install sdmx1
    
    import sdmx
    
    ECB = sdmx.Client("ECB")
    flow_msg = ECB.dataflow()   
    
    print(repr(flow_msg))                                                 
    

    gives:

    <sdmx.StructureMessage>                       
      <Header>                                                                                        
        id: 'IREF508443'                                                                              
        prepared: '2021-03-04T09:40:40+00:00'
        receiver: <Agency not_supplied>
        sender: <Agency Unknown>
        source: 
        test: False
      response: <Response [200]>
      DataflowDefinition (71): AME BKN BLS BNT BOP BSI BSP CBD CBD2 CCP CIS...
      DataStructureDefinition (55): ECB_AME1 ECB_BKN1 ECB_BLS1 ECB_BOP_BNT ...