Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication/session expires in 2-3 hours #139

Open
eantonya opened this issue Feb 23, 2025 · 2 comments
Open

Authentication/session expires in 2-3 hours #139

eantonya opened this issue Feb 23, 2025 · 2 comments

Comments

@eantonya
Copy link

eantonya commented Feb 23, 2025

I can log in and run whatever commands, but about 2-3 hours later the session expires and I start getting the error below. Deleting the session and logging in again works for a couple hours and then expires again. Any suggestions?

ClientResponseError                       Traceback (most recent call last)
File /opt/conda/lib/python3.11/site-packages/gql/transport/aiohttp.py:343, in AIOHTTPTransport.execute.<locals>.raise_response_error(resp, reason)
    341 try:
    342     # Raise a ClientResponseError if response status is 400 or higher
--> 343     resp.raise_for_status()
    344 except ClientResponseError as e:

File /opt/conda/lib/python3.11/site-packages/aiohttp/client_reqrep.py:1161, in ClientResponse.raise_for_status(self)
   1159     self.release()
-> 1161 raise ClientResponseError(
   1162     self.request_info,
   1163     self.history,
   1164     status=self.status,
   1165     message=self.reason,
   1166     headers=self.headers,
   1167 )

ClientResponseError: 401, message='Unauthorized', url='https://api.monarchmoney.com/graphql'

The above exception was the direct cause of the following exception:

TransportServerError                      Traceback (most recent call last)
Cell In[19], line 1
----> 1 await mm.get_accounts()

File /opt/conda/lib/python3.11/site-packages/monarchmoney/monarchmoney.py:212, in MonarchMoney.get_accounts(self)
    134 """
    135 Gets the list of accounts configured in the Monarch Money account.
    136 """
    137 query = gql(
    138     """
    139   query GetAccounts {
   (...)
    210 """
    211 )
--> 212 return await self.gql_call(
    213     operation="GetAccounts",
    214     graphql_query=query,
    215 )

File /opt/conda/lib/python3.11/site-packages/monarchmoney/monarchmoney.py:2768, in MonarchMoney.gql_call(self, operation, graphql_query, variables)
   2759 async def gql_call(
   2760     self,
   2761     operation: str,
   2762     graphql_query: DocumentNode,
   2763     variables: Dict[str, Any] = {},
   2764 ) -> Dict[str, Any]:
   2765     """
   2766     Makes a GraphQL call to Monarch Money's API.
   2767     """
-> 2768     return await self._get_graphql_client().execute_async(
   2769         document=graphql_query, operation_name=operation, variable_values=variables
   2770     )

File /opt/conda/lib/python3.11/site-packages/gql/client.py:367, in Client.execute_async(self, document, variable_values, operation_name, serialize_variables, parse_result, get_execution_result, **kwargs)
    365 """:meta private:"""
    366 async with self as session:
--> 367     return await session.execute(
    368         document,
    369         variable_values=variable_values,
    370         operation_name=operation_name,
    371         serialize_variables=serialize_variables,
    372         parse_result=parse_result,
    373         get_execution_result=get_execution_result,
    374         **kwargs,
    375     )

File /opt/conda/lib/python3.11/site-packages/gql/client.py:1628, in AsyncClientSession.execute(self, document, variable_values, operation_name, serialize_variables, parse_result, get_execution_result, **kwargs)
   1608 """Coroutine to execute the provided document AST asynchronously using
   1609 the async transport.
   1610 
   (...)
   1624 
   1625 The extra arguments are passed to the transport execute method."""
   1627 # Validate and execute on the transport
-> 1628 result = await self._execute(
   1629     document,
   1630     variable_values=variable_values,
   1631     operation_name=operation_name,
   1632     serialize_variables=serialize_variables,
   1633     parse_result=parse_result,
   1634     **kwargs,
   1635 )
   1637 # Raise an error if an error is returned in the ExecutionResult object
   1638 if result.errors:

File /opt/conda/lib/python3.11/site-packages/gql/client.py:1537, in AsyncClientSession._execute(self, document, variable_values, operation_name, serialize_variables, parse_result, **kwargs)
   1535 # Execute the query with the transport with a timeout
   1536 with fail_after(self.client.execute_timeout):
-> 1537     result = await self.transport.execute(
   1538         document,
   1539         variable_values=variable_values,
   1540         operation_name=operation_name,
   1541         **kwargs,
   1542     )
   1544 # Unserialize the result if requested
   1545 if self.client.schema:

File /opt/conda/lib/python3.11/site-packages/gql/transport/aiohttp.py:368, in AIOHTTPTransport.execute(self, document, variable_values, operation_name, extra_args, upload_files)
    365     await raise_response_error(resp, "Not a JSON answer")
    367 if "errors" not in result and "data" not in result:
--> 368     await raise_response_error(resp, 'No "data" or "errors" keys in answer')
    370 return ExecutionResult(
    371     errors=result.get("errors"),
    372     data=result.get("data"),
    373     extensions=result.get("extensions"),
    374 )

File /opt/conda/lib/python3.11/site-packages/gql/transport/aiohttp.py:345, in AIOHTTPTransport.execute.<locals>.raise_response_error(resp, reason)
    343     resp.raise_for_status()
    344 except ClientResponseError as e:
--> 345     raise TransportServerError(str(e), e.status) from e
    347 result_text = await resp.text()
    348 raise TransportProtocolError(
    349     f"Server did not return a GraphQL result: "
    350     f"{reason}: "
    351     f"{result_text}"
    352 )

TransportServerError: 401, message='Unauthorized', url='https://api.monarchmoney.com/graphql'```
@eantonya
Copy link
Author

Upon some further investigation I think it expires somewhere between 30 minutes and 1 hour.

@BrinksDaniel
Copy link

BrinksDaniel commented Feb 26, 2025

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants