Skip to content

Commit 326fa91

Browse files
author
Jonny Johannes
committed
urlencode query params
1 parent 9cb77be commit 326fa91

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

adoption_sources/rescue_groups.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import os
1010
import re
1111
from typing import Iterator
12+
from urllib.parse import urlencode
1213

1314
import requests
1415

16+
1517
from abstractions import AdoptablePet, PetSource
1618

1719
logger = logging.getLogger(__name__)
@@ -63,10 +65,9 @@ def fetch_pets(self) -> Iterator[AdoptablePet]:
6365
"Set CUTEPETSBOSTON_RESCUEGROUPS_API_KEY environment variable."
6466
)
6567

66-
url = f"{self.BASE_URL}/{self.species}"
67-
headers = {
68-
"Content-Type": "application/vnd.api+json",
69-
"Authorization": self._api_key,
68+
query_url_params = {
69+
'limit': 2,
70+
'sort': 'random'
7071
}
7172
payload = {
7273
# "filters": [
@@ -80,7 +81,12 @@ def fetch_pets(self) -> Iterator[AdoptablePet]:
8081
# "miles": self.radius_miles,
8182
# "postalcode": self.postal_code,
8283
# },
83-
"limit": 2,
84+
}
85+
query_string = urlencode(query_url_params)
86+
url = f"{self.BASE_URL}/{self.species}?{query_string}"
87+
headers = {
88+
"Content-Type": "application/vnd.api+json",
89+
"Authorization": self._api_key,
8490
}
8591

8692
logger.info(

0 commit comments

Comments
 (0)