benw-at-birdie
03/04/2024, 3:58 PM:
characters to be encoded as %3A
in parameter strings. For example curl -H "User-Agent: test" "<https://api.service.cqc.org.uk/public/v1/changes/location?startTimestamp=2024-03-04T00:00:00Z&endTimestamp=2024-03-04T15:32:24Z>"
is ok 🙂 but curl -H "User-Agent: test" "<https://api.service.cqc.org.uk/public/v1/changes/location?startTimestamp=2024-03-04T00%3A00%3A00Z&endTimestamp=2024-03-04T15%3A32%3A24Z>"
is not 😞 .
The version of the SDK we're currently using (which is at least a couple of years old) encodes timestamps in the latter format. To get around this we've got a hack... which is to override the rest stream class's prepare_request()
method like this...
def prepare_request(
self, context: Optional[dict], next_page_token: Optional[Any]
) -> requests.PreparedRequest:
request = super().prepare_request(context, next_page_token)
request.headers["User-Agent"] = self.config["partner_code"]
request.url = request.url.replace("%3A", ":")
return request
But is there a more elegant way to control how the SDK encodes special characters?
cc @miguel_sotomayorptd
03/04/2024, 4:10 PMEdgar Ramírez (Arch.dev)
03/04/2024, 5:14 PMbenw-at-birdie
03/04/2024, 5:37 PM