Skip to content

Commit f91affe

Browse files
Raphael Lullisrakanalh
authored andcommitted
Change method of getting json data out of HTTP requests
The requests module has some undercover magic of using a different implementation depending on whether the simplejson package is installed, which makes the built-in requests.response.json() method unreliable To avoid this issue, we are removing all calls to response.json() and parsing the response using python's built-in json module.
1 parent 6924d58 commit f91affe

File tree

7 files changed

+170
-141
lines changed

7 files changed

+170
-141
lines changed

raiden/network/pathfinding.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,19 @@ def get_last_iou(
279279
signature = to_hex(LocalSigner(privkey).sign(signature_data))
280280

281281
try:
282-
data = (
283-
requests.get(
284-
f"{url}/api/v1/{to_checksum_address(token_network_address)}/payment/iou",
285-
params=dict(
286-
sender=to_checksum_address(sender),
287-
receiver=to_checksum_address(receiver),
288-
timestamp=timestamp,
289-
signature=signature,
290-
),
291-
timeout=DEFAULT_HTTP_REQUEST_TIMEOUT,
292-
)
293-
.json()
294-
.get("last_iou")
282+
response = requests.get(
283+
f"{url}/api/v1/{to_checksum_address(token_network_address)}/payment/iou",
284+
params=dict(
285+
sender=to_checksum_address(sender),
286+
receiver=to_checksum_address(receiver),
287+
timestamp=timestamp,
288+
signature=signature,
289+
),
290+
timeout=DEFAULT_HTTP_REQUEST_TIMEOUT,
295291
)
296292

293+
data = json.loads(response.content).get("last_iou")
294+
297295
if data is None:
298296
return None
299297

raiden/network/resolver/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from http import HTTPStatus
23
from typing import TYPE_CHECKING
34

@@ -52,7 +53,7 @@ def reveal_secret_with_resolver(
5253

5354
state_change = ReceiveSecretReveal(
5455
sender=secret_request_event.recipient,
55-
secret=Secret(to_bytes(hexstr=response.json()["secret"])),
56+
secret=Secret(to_bytes(hexstr=json.loads(response.content)["secret"])),
5657
)
5758
raiden.handle_and_track_state_changes([state_change])
5859
return True

0 commit comments

Comments
 (0)