From 8786e7eea2a63f4adb09c598302d7246d0c76310 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:34:20 -0500 Subject: [PATCH 1/2] Add timeout to `requests` calls (#1) Co-authored-by: pixeebot[bot] <23113631+pixeebot@users.noreply.github.com> --- modules/pinata_api.py | 12 ++++++------ scripts/query_graph.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/pinata_api.py b/modules/pinata_api.py index c0c0101..c379fa6 100644 --- a/modules/pinata_api.py +++ b/modules/pinata_api.py @@ -31,7 +31,7 @@ def pinJSONToIPFS( } endpoint_uri = "https://api.pinata.cloud/pinning/pinJSONToIPFS" - response = requests.post(endpoint_uri, headers=HEADERS, json=ipfs_json) + response = requests.post(endpoint_uri, headers=HEADERS, json=ipfs_json, timeout=60) return response.json() @@ -61,8 +61,8 @@ def pinContentToIPFS( with Path(filepath).open("rb") as fp: image_binary = fp.read() response = requests.post( - endpoint_uri, files={"file": (filename, image_binary)}, headers=HEADERS - ) + endpoint_uri, files={"file": (filename, image_binary)}, headers=HEADERS, + timeout=60) print(response.json()) # response = requests.post(endpoint_uri, data=multipart_form_data, headers=HEADERS) @@ -90,7 +90,7 @@ def pinSearch( "pinata_api_key": pinata_api_key, "pinata_secret_api_key": pinata_secret, } - response = requests.get(endpoint_uri, headers=HEADERS).json() + response = requests.get(endpoint_uri, headers=HEADERS, timeout=60).json(timeout=60) # now get the actual data from this data = [] @@ -99,8 +99,8 @@ def pinSearch( for item in response["rows"]: ipfs_pin_hash = item["ipfs_pin_hash"] hash_data = requests.get( - f"https://gateway.pinata.cloud/ipfs/{ipfs_pin_hash}" - ).json() + f"https://gateway.pinata.cloud/ipfs/{ipfs_pin_hash}", + timeout=60).json(timeout=60) data.append(hash_data) # print(response.json()) diff --git a/scripts/query_graph.py b/scripts/query_graph.py index 2e8e683..9569fa3 100644 --- a/scripts/query_graph.py +++ b/scripts/query_graph.py @@ -32,7 +32,7 @@ def query_subgraph(api_endpoint: str, address: str, entity_name: str) -> List: """ ) - request = requests.post(api_endpoint, json={"query": query}) + request = requests.post(api_endpoint, json={"query": query}, timeout=60) if request.status_code == 200: if "errors" in request.json(): From e9ded6bc7d3b60823bc4a043f923c80ba6abed81 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <23113631+pixeebot@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:23:48 +0000 Subject: [PATCH 2/2] Sandbox URL Creation --- modules/pinata_api.py | 10 ++++------ requirements.txt | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/pinata_api.py b/modules/pinata_api.py index c379fa6..5b56927 100644 --- a/modules/pinata_api.py +++ b/modules/pinata_api.py @@ -1,8 +1,7 @@ -import json -from typing import Type, Union, Dict, Any, List +from typing import Dict, Any, List import requests -import os from pathlib import Path +from security import safe_requests def pinJSONToIPFS( @@ -90,7 +89,7 @@ def pinSearch( "pinata_api_key": pinata_api_key, "pinata_secret_api_key": pinata_secret, } - response = requests.get(endpoint_uri, headers=HEADERS, timeout=60).json(timeout=60) + response = safe_requests.get(endpoint_uri, headers=HEADERS, timeout=60).json(timeout=60) # now get the actual data from this data = [] @@ -98,8 +97,7 @@ def pinSearch( for item in response["rows"]: ipfs_pin_hash = item["ipfs_pin_hash"] - hash_data = requests.get( - f"https://gateway.pinata.cloud/ipfs/{ipfs_pin_hash}", + hash_data = safe_requests.get(f"https://gateway.pinata.cloud/ipfs/{ipfs_pin_hash}", timeout=60).json(timeout=60) data.append(hash_data) diff --git a/requirements.txt b/requirements.txt index 7799c51..288333d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ streamlit web3 -requests \ No newline at end of file +requests +security~=1.2.0