Skip to content

Commit 1cde54f

Browse files
committed
increased request timeout on pay_offer method to 20s
1 parent f4ccedd commit 1cde54f

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

fewsats/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ def __init__(self,
3333
def _request(self: Fewsats,
3434
method: str, # The HTTP method to use
3535
path: str, # The path to request
36+
timeout: int = 10, # Timeout for the request in s
3637
**kwargs) -> Dict[str, Any]:
3738
"Makes an authenticated request to Fewsats API"
3839
url = f"{self.base_url}/{path}"
39-
return self._httpx_client.request(method, url, **kwargs)
40+
return self._httpx_client.request(method, url, timeout=timeout, **kwargs)
4041

4142
# %% ../nbs/00_core.ipynb 14
4243
@patch
@@ -133,7 +134,7 @@ def pay_offer(self:Fewsats,
133134
134135
Returns payment status response"""
135136
data = {"payment_method": payment_method, **l402_offer} if payment_method else l402_offer
136-
return self._request("POST", "v0/l402/purchases/from-offer", json=data)
137+
return self._request("POST", "v0/l402/purchases/from-offer", timeout=20, json=data)
137138

138139
# %% ../nbs/00_core.ipynb 46
139140
@patch

nbs/00_core.ipynb

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@
126126
"def _request(self: Fewsats, \n",
127127
" method: str, # The HTTP method to use\n",
128128
" path: str, # The path to request\n",
129+
" timeout: int = 10, # Timeout for the request in s\n",
129130
" **kwargs) -> Dict[str, Any]:\n",
130131
" \"Makes an authenticated request to Fewsats API\"\n",
131132
" url = f\"{self.base_url}/{path}\"\n",
132-
" return self._httpx_client.request(method, url, **kwargs)"
133+
" return self._httpx_client.request(method, url, timeout=timeout, **kwargs)"
133134
]
134135
},
135136
{
@@ -208,7 +209,7 @@
208209
" 'billing_info': None,\n",
209210
" 'id': 15,\n",
210211
" 'created_at': '2024-12-18T18:19:00.531Z',\n",
211-
" 'webhook_url': 'https://api.fewsats.com'})"
212+
" 'webhook_url': 'https://example.com'})"
212213
]
213214
},
214215
"execution_count": null,
@@ -250,7 +251,7 @@
250251
{
251252
"data": {
252253
"text/plain": [
253-
"(200, [{'id': 15, 'balance': 2374, 'currency': 'usd'}])"
254+
"(200, [{'id': 15, 'balance': 2373, 'currency': 'usd'}])"
254255
]
255256
},
256257
"execution_count": null,
@@ -398,7 +399,7 @@
398399
" 'title': 'Test Package',\n",
399400
" 'payment_methods': ['lightning', 'credit_card'],\n",
400401
" 'type': 'one-off'}],\n",
401-
" 'payment_context_token': '8a49b581-ab9e-4469-979c-187261303b7a',\n",
402+
" 'payment_context_token': '8eff76bf-1d99-4dc2-b6b7-537ef2b62998',\n",
402403
" 'payment_request_url': 'https://api.fewsats.com/v0/l402/payment-request',\n",
403404
" 'version': '0.2.2'})"
404405
]
@@ -458,9 +459,9 @@
458459
"data": {
459460
"text/plain": [
460461
"(200,\n",
461-
" {'expires_at': '2025-02-10T14:53:01.452963+00:00',\n",
462+
" {'expires_at': '2025-02-27T06:38:36.838131+00:00',\n",
462463
" 'offer_id': 'test_offer_2',\n",
463-
" 'payment_request': {'lightning_invoice': 'lnbc100n1pn65z5mpp5jxd6gk0536wxdx3trktg7kxk6egxx58qrj2xkrpkvs4j3msljx2sdq523jhxapq2pskx6mpvajscqzpgxqrzpjrzjqwghf7zxvfkxq5a6sr65g0gdkv768p83mhsnt0msszapamzx2qvuxqqqqz99gpz55yqqqqqqqqqqqqqq9qrzjq25carzepgd4vqsyn44jrk85ezrpju92xyrk9apw4cdjh6yrwt5jgqqqqz99gpz55yqqqqqqqqqqqqqq9qsp5ymum4ydvhkxuusxa607cjlgrufxs7w7yqltj4228nh78g6s5xlps9qxpqysgq9ugkyrjzusq0cj6zs8dtq77r4h0kxjau6fc35gyydmt2a02hnvaz4zmnjgaplgnj3dc5pjvf8qcg3j3dkq4d62crgy9hqqz9t7v0ndqquj387a'},\n",
464+
" 'payment_request': {'lightning_invoice': 'lnbc110n1pnuqqp6pp58ecgelkk7x7f3k785hhcpa6pnmq03w60302vne3wt2v7xltm35kqdq523jhxapq2pskx6mpvajscqzpgxqrzpjrzjqwghf7zxvfkxq5a6sr65g0gdkv768p83mhsnt0msszapamzx2qvuxqqqqz99gpz55yqqqqqqqqqqqqqq9qrzjq25carzepgd4vqsyn44jrk85ezrpju92xyrk9apw4cdjh6yrwt5jgqqqqz99gpz55yqqqqqqqqqqqqqq9qsp5tup74y2nsk5q8e03cae0apdr28x2m3eav94lurywpl02j7sv5p3s9qxpqysgqal7sefttee3xlh3x87q7fvqnwaa56fzd8q8w5tpa62u9vywutrmylxxmdfez82d5saj89vjz30y79prxuedt3a6aylrk32lt0dvtlvcqkx0a8r'},\n",
464465
" 'version': '0.2.2'})"
465466
]
466467
},
@@ -506,7 +507,7 @@
506507
"data": {
507508
"text/plain": [
508509
"(200,\n",
509-
" {'payment_context_token': '8a49b581-ab9e-4469-979c-187261303b7a',\n",
510+
" {'payment_context_token': '8eff76bf-1d99-4dc2-b6b7-537ef2b62998',\n",
510511
" 'status': 'pending',\n",
511512
" 'offer_id': None,\n",
512513
" 'paid_at': None,\n",
@@ -608,13 +609,13 @@
608609
"data": {
609610
"text/plain": [
610611
"(200,\n",
611-
" {'id': 300,\n",
612-
" 'created_at': '2025-02-10T14:18:20.217Z',\n",
612+
" {'id': 313,\n",
613+
" 'created_at': '2025-02-27T06:03:40.805Z',\n",
613614
" 'status': 'success',\n",
614615
" 'payment_request_url': '',\n",
615616
" 'payment_context_token': '',\n",
616-
" 'invoice': 'lnbc100n1pn65z5mpp5jxd6gk0536wxdx3trktg7kxk6egxx58qrj2xkrpkvs4j3msljx2sdq523jhxapq2pskx6mpvajscqzpgxqrzpjrzjqwghf7zxvfkxq5a6sr65g0gdkv768p83mhsnt0msszapamzx2qvuxqqqqz99gpz55yqqqqqqqqqqqqqq9qrzjq25carzepgd4vqsyn44jrk85ezrpju92xyrk9apw4cdjh6yrwt5jgqqqqz99gpz55yqqqqqqqqqqqqqq9qsp5ymum4ydvhkxuusxa607cjlgrufxs7w7yqltj4228nh78g6s5xlps9qxpqysgq9ugkyrjzusq0cj6zs8dtq77r4h0kxjau6fc35gyydmt2a02hnvaz4zmnjgaplgnj3dc5pjvf8qcg3j3dkq4d62crgy9hqqz9t7v0ndqquj387a',\n",
617-
" 'preimage': '4e17a5ec0606daf55afd55f81b9fb0bc963eb53182b1b56ce73e6e3535c1c63b',\n",
617+
" 'invoice': 'lnbc110n1pnuqqp6pp58ecgelkk7x7f3k785hhcpa6pnmq03w60302vne3wt2v7xltm35kqdq523jhxapq2pskx6mpvajscqzpgxqrzpjrzjqwghf7zxvfkxq5a6sr65g0gdkv768p83mhsnt0msszapamzx2qvuxqqqqz99gpz55yqqqqqqqqqqqqqq9qrzjq25carzepgd4vqsyn44jrk85ezrpju92xyrk9apw4cdjh6yrwt5jgqqqqz99gpz55yqqqqqqqqqqqqqq9qsp5tup74y2nsk5q8e03cae0apdr28x2m3eav94lurywpl02j7sv5p3s9qxpqysgqal7sefttee3xlh3x87q7fvqnwaa56fzd8q8w5tpa62u9vywutrmylxxmdfez82d5saj89vjz30y79prxuedt3a6aylrk32lt0dvtlvcqkx0a8r',\n",
618+
" 'preimage': '93de3658feeba62f6156001ac0a2a16e7bfe2b41f64417beea3e2b93b3b904c4',\n",
618619
" 'amount': 1,\n",
619620
" 'currency': 'usd',\n",
620621
" 'payment_method': 'lightning',\n",
@@ -643,12 +644,12 @@
643644
{
644645
"data": {
645646
"text/plain": [
646-
"{'payment_context_token': '8a49b581-ab9e-4469-979c-187261303b7a',\n",
647-
" 'status': 'success',\n",
648-
" 'offer_id': 'test_offer_2',\n",
649-
" 'paid_at': '2025-02-10T14:18:24.596788+00:00',\n",
650-
" 'amount': 1,\n",
651-
" 'currency': 'USD'}"
647+
"{'payment_context_token': '8eff76bf-1d99-4dc2-b6b7-537ef2b62998',\n",
648+
" 'status': 'pending',\n",
649+
" 'offer_id': None,\n",
650+
" 'paid_at': None,\n",
651+
" 'amount': None,\n",
652+
" 'currency': None}"
652653
]
653654
},
654655
"execution_count": null,
@@ -692,7 +693,7 @@
692693
"\n",
693694
" Returns payment status response\"\"\"\n",
694695
" data = {\"payment_method\": payment_method, **l402_offer} if payment_method else l402_offer\n",
695-
" return self._request(\"POST\", \"v0/l402/purchases/from-offer\", json=data)"
696+
" return self._request(\"POST\", \"v0/l402/purchases/from-offer\", timeout=20, json=data)"
696697
]
697698
},
698699
{
@@ -704,7 +705,7 @@
704705
"data": {
705706
"text/plain": [
706707
"(400,\n",
707-
" '{\"detail\": \"Invalid payment request received. Could not get payment details. Traceback (most recent call last):\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/connection.py\\\\\", line 198, in _new_conn\\\\n sock = connection.create_connection(\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/util/connection.py\\\\\", line 60, in create_connection\\\\n for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/socket.py\\\\\", line 976, in getaddrinfo\\\\n for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\nsocket.gaierror: [Errno -2] Name or service not known\\\\n\\\\nThe above exception was the direct cause of the following exception:\\\\n\\\\nTraceback (most recent call last):\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py\\\\\", line 787, in urlopen\\\\n response = self._make_request(\\\\n ^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py\\\\\", line 488, in _make_request\\\\n raise new_e\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py\\\\\", line 464, in _make_request\\\\n self._validate_conn(conn)\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py\\\\\", line 1093, in _validate_conn\\\\n conn.connect()\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/connection.py\\\\\", line 704, in connect\\\\n self.sock = sock = self._new_conn()\\\\n ^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/connection.py\\\\\", line 205, in _new_conn\\\\n raise NameResolutionError(self.host, self, e) from e\\\\nurllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object>: Failed to resolve \\'api.lightspark.com\\' ([Errno -2] Name or service not known)\\\\n\\\\nThe above exception was the direct cause of the following exception:\\\\n\\\\nTraceback (most recent call last):\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/requests/adapters.py\\\\\", line 667, in send\\\\n resp = conn.urlopen(\\\\n ^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py\\\\\", line 841, in urlopen\\\\n retries = retries.increment(\\\\n ^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py\\\\\", line 519, in increment\\\\n raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\nurllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=\\'api.lightspark.com\\', port=443): Max retries exceeded with url: /graphql/server/2023-09-13 (Caused by NameResolutionError(\\\\\"<urllib3.connection.HTTPSConnection object>: Failed to resolve \\'api.lightspark.com\\' ([Errno -2] Name or service not known)\\\\\"))\\\\n\\\\nDuring handling of the above exception, another exception occurred:\\\\n\\\\nTraceback (most recent call last):\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/ninja/operation.py\\\\\", line 341, in run\\\\n result = await self.view_func(request, **values)\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/opt/hub_api/l402/api/common/decorators.py\\\\\", line 17, in wrapper\\\\n return await func(request, *args, **kwargs)\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/opt/hub_api/l402/api/v0/views.py\\\\\", line 127, in create_payment_request_v0\\\\n return await create_payment_request(\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/opt/hub_api/l402/server.py\\\\\", line 68, in create_payment_request\\\\n provider = LightningProvider()\\\\n ^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/opt/hub_api/l402/providers/lightning.py\\\\\", line 22, in __init__\\\\n self.client = LightsparkAPI()\\\\n ^^^^^^^^^^^^^^^\\\\n File \\\\\"/opt/hub_api/l402/utils/lightspark_api.py\\\\\", line 38, in __init__\\\\n signing_key = self.client.recover_node_signing_key(self.node_id, self.node_password)\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/lightspark/lightspark_client.py\\\\\", line 502, in recover_node_signing_key\\\\n json = self._requester.execute_graphql(\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/lightspark/requests/requester.py\\\\\", line 96, in execute_graphql\\\\n r = self.graphql_session.post(\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/requests/sessions.py\\\\\", line 637, in post\\\\n return self.request(\\\\\"POST\\\\\", url, data=data, json=json, **kwargs)\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/requests/sessions.py\\\\\", line 589, in request\\\\n resp = self.send(prep, **send_kwargs)\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/requests/sessions.py\\\\\", line 703, in send\\\\n r = adapter.send(request, **kwargs)\\\\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\\\n File \\\\\"/usr/local/lib/python3.12/site-packages/requests/adapters.py\\\\\", line 700, in send\\\\n raise ConnectionError(e, request=request)\\\\nrequests.exceptions.ConnectionError: HTTPSConnectionPool(host=\\'api.lightspark.com\\', port=443): Max retries exceeded with url: /graphql/server/2023-09-13 (Caused by NameResolutionError(\\\\\"<urllib3.connection.HTTPSConnection object>: Failed to resolve \\'api.lightspark.com\\' ([Errno -2] Name or service not known)\\\\\"))\\\\n\"}')"
708+
" '{\"detail\": \"Invalid payment request received. Could not get payment details. {\\\\\"detail\\\\\": \\\\\"Invalid payment request received. Payment context token \\'8eff76bf-1d99-4dc2-b6b7-537ef2b62998\\' already used\\\\\"}\"}')"
708709
]
709710
},
710711
"execution_count": null,

0 commit comments

Comments
 (0)