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

RuntimeError when using key on data request #94

Open
apfister opened this issue Jul 1, 2022 · 1 comment
Open

RuntimeError when using key on data request #94

apfister opened this issue Jul 1, 2022 · 1 comment
Assignees
Labels
needs-info Needs more info from the issuer to proceed

Comments

@apfister
Copy link

apfister commented Jul 1, 2022

When running this code, I receive a RuntimeError shown below:

spc = sdmx.Client('spc')

key = dict(FREQ=['A'])
params = dict(startPeriod='2021', endPeriod='2022')

data = spc.data('DF_SDG', key=key, params=params)

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
File ~/opt/anaconda3/lib/python3.8/site-packages/sdmx/reader/xml.py:242, in Reader.read_message(self, source, dsd)
    240 try:
    241     # Parse the element
--> 242     result = func(self, element)
    243 except TypeError:

File ~/opt/anaconda3/lib/python3.8/site-packages/sdmx/reader/xml.py:1126, in _ms(reader, elem)
   1125 else:
-> 1126     raise RuntimeError
   1128 if arg["values_for"] is None:

RuntimeError: 

The above exception was the direct cause of the following exception:

XMLParseError                             Traceback (most recent call last)
/Users/adam6475/dev/sdg-template-connectors/sdmx/retry.ipynb Cell 9' in <cell line: 6>()
      [3](vscode-notebook-cell:/Users/adam6475/dev/sdg-template-connectors/sdmx/retry.ipynb#ch0000009?line=2) key = dict(FREQ=['A'])
      [4](vscode-notebook-cell:/Users/adam6475/dev/sdg-template-connectors/sdmx/retry.ipynb#ch0000009?line=3) params = dict(startPeriod='2021', endPeriod='2022')
----> [6](vscode-notebook-cell:/Users/adam6475/dev/sdg-template-connectors/sdmx/retry.ipynb#ch0000009?line=5) data = spc.data('DF_SDG', key=key, params=params)

File ~/opt/anaconda3/lib/python3.8/site-packages/sdmx/client.py:440, in Client.get(self, resource_type, resource_id, tofile, use_cache, dry_run, **kwargs)
    438     req = self._request_from_url(kwargs)
...
    263 
    264 # Remove some internal items
    265 self.pop_single("SS without DSD")

XMLParseError: RuntimeError

if you run the code without the key parameters, there is no error:

spc = sdmx.Client('spc')

# key = dict(FREQ=['A'])
params = dict(startPeriod='2021', endPeriod='2022')

data = spc.data('DF_SDG', params=params)

image

@khaeru
Copy link
Owner

khaeru commented Jul 14, 2022

Thanks for the report!

File ~/opt/anaconda3/lib/python3.8/site-packages/sdmx/reader/xml.py:1126, in _ms(reader, elem)
   1125 else:
-> 1126     raise RuntimeError

This (_ms(reader, elem)) indicates the error occurs when parsing a MemberSelection object from an XML <com:Attribute> or <com:KeyValue> tag. This is probably either (a) some valid SDMX feature/usage that we have not seen in the wild, or (b) some invalid SDMX being returned by this data provider.

The log output should give the exact URL that is queried. Can you please give this URL and/or attach the XML file that is returned? This will help me to:

  • Diagnose what about the contents is triggering the code.
  • Fix, e.g. for (a) by improving the implementation, or for (b) by applying a mitigation for this source in particular.
  • Add a test to confirm the fix works.

@khaeru khaeru self-assigned this Jul 14, 2022
@khaeru khaeru added the needs-info Needs more info from the issuer to proceed label Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-info Needs more info from the issuer to proceed
Projects
None yet
Development

No branches or pull requests

2 participants