0

我正在使用请求包表单 pandasdmx 库来访问欧洲中央银行的一些汇率。我尝试遵循以下演练中突出显示的步骤:https ://pandasdmx.readthedocs.io/en/v1.0/walkthrough.html# bur,当我尝试访问不同的数据流时,它给了我一个错误。这是我正在使用的代码:

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.

我以前多次使用过这种访问方式,没有出现任何问题。¿ 有人知道会发生什么吗?

4

1 回答 1

1

ECB 更改了其 Web 服务 URL,而pandaSDMX您拥有的版本没有当前 URL。我建议使用sdmx17 个月前修复此问题的软件包(请参阅此处的差异):

$ pip install sdmx1
import sdmx

ECB = sdmx.Client("ECB")
flow_msg = ECB.dataflow()   

print(repr(flow_msg))                                                 

给出:

<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 ...
于 2021-03-04T09:51:46.253 回答