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

Trying to get WB WDI working #206

Open
nicolas-graves opened this issue Nov 4, 2024 · 6 comments
Open

Trying to get WB WDI working #206

nicolas-graves opened this issue Nov 4, 2024 · 6 comments
Labels
data-source Issues related to specific web services/data source(s) needs-info Needs more info from the issuer to proceed

Comments

@nicolas-graves
Copy link

nicolas-graves commented Nov 4, 2024

One more issue ;)

I'm also trying to use the WB WDI database, which should in principle have enough to be working, but is not. I'm currently working on the issue, this is to record my progress and get some feedback.

modified   sdmx/source/wb_wdi.py
@@ -11,8 +11,10 @@ class Source(BaseSource):
         if kwargs["resource_type"] == "categoryscheme":
             # Service does not respond to requests for "WB" category schemes
             kwargs["provider"] = "all"
-        elif kwargs["resource_type"] != "data":
+        elif kwargs["resource_type"] == "data":
             # Provider's own ID differs from its ID in this package
+            kwargs["provider"] = "WDI"
+        elif kwargs["resource_type"] != "dataflow":
             kwargs.setdefault("provider", "WB")

Now it's currently failing with

import sdmx
wdi = sdmx.Client("WB_WDI")
wdi.dataflow("A.SP_POP_TOTL.AFG", force=True)

Traceback (most recent call last):
  File "/home/graves/projects/src/sdmx/scratch.py", line 10, in <module>
    wdi.dataflow("A.SP_POP_TOTL.AFG", force=True)
  File "/home/graves/projects/src/sdmx/sdmx/client.py", line 465, in get
    response.raise_for_status()
  File "/home/graves/.guix-profile/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: http://dataapi.worldbank.org/v2/sdmx/rest/dataflow/WB_WDI/A.SP_POP_TOTL.AFG/latest/?references=all

Almost seems the right url, but I guess my current issue is that an involuntary / finds its way in the original url.

How I would have tackled that : define a url kwarg in modify_request_args that will override the one passed by default. Maybe there's also a way to avoid that additional / when the key kwarg is None or non-existent?

@khaeru
Copy link
Owner

khaeru commented Nov 5, 2024

One quick check: I see http://, but this has been updated on main; see commit 7dc758e

Does using this fix the error?

@nicolas-graves
Copy link
Author

I'll check but I'm pretty sure that yes, it seems this is the redirect operated after the first request (dataapi prefix instead of api).

@khaeru khaeru added data-source Issues related to specific web services/data source(s) needs-info Needs more info from the issuer to proceed labels Nov 5, 2024
@nicolas-graves
Copy link
Author

nicolas-graves commented Nov 5, 2024

@khaeru
Copy link
Owner

khaeru commented Nov 5, 2024

In these, A.SP_POP_TOTL.AFG looks an awful lot like a key (values for certain dimensions). Keys are valid parts of /data/… requests (to get a DataMessage, per the example you give from the WB documentation), but for a …/dataflow/ request (to get a StructureMessage with the DataflowDefinition) they are not relevant. One should use instead the ID of the given data flow.

@nicolas-graves
Copy link
Author

Will work from now on in https://github.com/CIRED/sdmx/tree/wdi and submit a PR when things are working on my end.

@nicolas-graves
Copy link
Author

#208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data-source Issues related to specific web services/data source(s) needs-info Needs more info from the issuer to proceed
Projects
None yet
Development

No branches or pull requests

2 participants