When creating a Strapi client in Python using the requests module I came across a problem.
When using the params argument for the requests.get
method with a nested dictionary it doesn't translate to a querystring like the npm package qs
does.
I wanted a qs.stringify
in python but found the answer nowhere on Stack Overflow.
I found this package: https://github.com/cine-io/nested-query-string
def _get(self, path, params=None, **kwargs):
url = self.__construct_url(path)
headers = self.__get_request_headers()
if params is not None:
#see line here!!
from nested_query_string import NestedQueryString
params = NestedQueryString.encode(params)
response = requests.get(url, params=params, headers=headers, **kwargs)
assert response.status_code == 200
return self.__parse_strapi_response(response)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.